allPlaylists is a vector of type Playlist.
listSongs is a vector of type *Songs.
//Loop that goes through each element in the playlist vector.
for(int k = 0; k < allPlaylists.size(); k++)
{
// loop that goes through each song within the Playlist vector element. listSongs is a vector of Song pointers.
for (int g = 0; g < (allPlaylists.at(k).listSongs.size() - 1); g++)
{
// Checks if songDelete (input earlier) is an element in any of the playlists.
// If it is, checks if artistDelete is an element of that of the playlist for that song.
if(songDelete == allPlaylists.at(k).listSongs.at(g)->getSongName())
if(artistDelete == allPlaylists.at(k).listSongs.at(g).getArtistName())
{
// If the song and artist exist, I delete that song element from the vector listSongs, and output a message. allPlaylists.at(k).listSongs.erase(allPlaylists.at(k).listSongs.begin() + g);
cout << songDelete << "was deleted from your " << allPlaylists.at(k).getPlaylistName() << " playlist." << endl;
continue;
}
}
// Then I delete the element from the entire music library. library is a vector of Song objects.
cout << songDelete << " was deleted from the library." << endl;
break;
}
No matter what I do, I get a Seg Fault. I think I need to erase the Playlist pointers to the songs before I can erase the song object in library, right?