My model is quite simple but I’m having some problems with the vector I’m using.
Basically, I have a Song class that has one playlist, and a Playlist can have multiple track (inside a vector).
Song* song = new Song("Rien de rien", "Biggy", 120);
Playlist* playlist;
Track* synthTrack;
playlist->addTrack(synthTrack); // without this line everything works fine
song->setPlaylist(playlist);
cout << "Title " + song->getTitle() << endl;
The console isn’t giving me any errors, but the cout isn’t showing up. This happens as soon as I add a track to my playlist.
This is what my Playlist class looks like:
class Playlist {
private:
vector<Track*> tracklist;
public:
void addTrack(Track* track){
this->tracklist.push_back(track);
}
};
@Lucian has already given a reasonable start at fixing the problem you’ve seen, but I’d advocate a somewhat different route. I’d start by getting rid of all the pointers in the relevant code:
…and:
Needing pointers is fairly unusual to start with, and when you do need them, you almost certainly want to wrap them in some sort of smart pointer class. In this case, I see no hint that the latter is necessary or probably even useful though.