[Solved] C++ Pointers or References [closed]


I don’t really understand exactly what you are asking, but it sounds like you want to have a way to get the album from a PlaylistTrack.

class PlaylistTrack : public Track
{
 public:
     PlaylistTrack(Album * owner){ m_owner = owner; }
     Album* getAlbum(){return m_owner;}
 private:
     Album* m_owner;

}

int main()
{

Album albumA;
PlaylistTrack newTrack(&albumA);

//Now the track knows what album it belongs to, but the album does not own the track    yet.
std::cout << "New Track's Album: " << newTrack.getAlbum.getTitle() << std::endl;

//Now the album owns this track
albumA.addTrack(newTrack);

//The PlaylistTrack constructor could add itself to the album if you wanted to I think.

return 0;
}

1

solved C++ Pointers or References [closed]