[英]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.