【问题标题】:Iterating Over Vector of classes in c++在 C++ 中迭代类的向量
【发布时间】:2013-01-02 05:15:04
【问题描述】:

歌曲是一门课 我想访问它的公共方法之一

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的一些特性,也许是Intellisense?你应该说清楚。你的问题不是关于 C++,而是关于你的 IDE

标签: c++ class methods vector iterator


【解决方案1】:

如果它没有向您显示内容,您可以帮助他。 (他是你的 IDE)

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

代码的作用几乎相同,但是您可以在调试器中快速观看并使用关于 Song 类型的对象歌曲的 AutoCompletion。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-01
    • 1970-01-01
    • 2012-11-19
    • 2015-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多