简体   繁体   中英

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM