• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C++ merging objects from different classes

JumBie

Golden Member
If i have two classes say for example:

Class Artist, and Class Song.

Artist holds: string name, and string genre.
Song holds: string songName, and int year.

If i create an object from artist and another object from song could i merge these two together?

So i create: Artist Me, and Song s1. Can I merge them together so when I cout the object it links the artist name and genre to the song name and year, and the artist can hold as many objects of Song as there is on an album?

For instance, can i make 10 objects of song, and link them all to one object from Artist? and then theoretically make Class Album, and link them all to an object from album?
 
You mean an Artist class that contains Albums, which contains Songs? If so, sure.

Code:
class Song
{
...
}

class Album
{
vector<Song> songs; // or array, whatever
...
}

class Artist
{
vector<Album> albums;
...
}
 
You mean an Artist class that contains Albums, which contains Songs? If so, sure.

Code:
class Song
{
...
}

class Album
{
vector<Song> songs; // or array, whatever
...
}

class Artist
{
vector<Album> albums;
...
}

Yeah, you lost me.

I am not sure how to store objects of classes within a Vector.
 
Back
Top