在c++中迭代类的Vector
Iterating Over Vector of classes in c++
Song是一个类我想访问它的一个公共方法
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和使用AutoCompletion关于song类型的对象song
相关文章:
- std::vector::迭代器是否可以合法地作为指针
- 从 std::vector 迭代器中执行函数指针
- 基于 C++ 范围的 std::vector 迭代的顺序
- c std :: vector迭代器构造函数,first == last
- 为什么通过"std::vector"迭代比通过"std::array"迭代更快
- 为什么 std::vector 迭代器在 erase() 调用后失效?
- Vector::迭代器在与开始比较时崩溃
- 为自定义类继承std::vector::迭代器
- 为什么 vector::迭代器在重新分配时失效
- C++ std::vector 迭代器错误
- 如何拥有:map<T,vector<迭代器来映射自身> >?
- 为什么std::vector迭代器在重新分配其他向量时无效
- 试图让Vector迭代器以不同的顺序进行迭代
- 处理vector迭代中的访问冲突异常
- vector的vector迭代器
- 使用std::vector::迭代器修改存储在std::vector中的值
- 迭代并移除Vector中的元素.错误:Vector迭代器不可递增
- 将vector迭代器转换为成员指针
- Vector迭代器在类中不兼容
- 调试断言:Vector迭代器不兼容(c++)