繁体   English   中英

在C ++中的类的Vector上迭代

[英]Iterating Over Vector of classes in c++

歌曲是一门课程,我想访问其中的一种公共方法

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;

}

为什么不向我显示迭代器的内容?

如果未向您显示内容,则可以帮助他。 (他是您的IDE)

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

该代码的功能几乎相同,但是您可以在调试器中使用QuickWatch并对类型为Song的对象歌曲使用AutoCompletion。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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