Christine
Christine

Reputation: 113

Iterating Over Vector of classes in c++

Song is a class and i want to access one of it's public methods

class RadioManager {

    std::vector<Song> all_songs;
public:

void addSong(const Song& song);

}

void mtm::RadioManager::addSong(const Song& song){

vector<Song>::iterator i;

    for (i = all_songs.begin(); i != all_songs.end(); ++i) {

    i->getSongName(); // When i type i-> i don't get the list of methods in the class song;

}

why it's not showing me contents of the iterator ?

Upvotes: 0

Views: 4181

Answers (1)

Stephane Rolland
Stephane Rolland

Reputation: 39926

If it doesn't show you the content, you can help him. (Him being your IDE)

for (i = all_songs.begin(); i != all_songs.end(); ++i) 
{
    Song& song = *i;
    song.getSongName(); 
}

the code does all most the same, but then you can QuickWatch and use AutoCompletion about the object song of type Song in your debugger.

Upvotes: 2

Related Questions