我有一个Playlist
类,它具有一个向量Tracks
,每个Track
有一个multimap<long, Note>
作为datamember。多图迭代器不工作
class Track {
private:
multimap<long, Note> noteList;
}
使用迭代器来存取权限的曲目是没有问题的,所以在这里这部分工作正常:
vector<Track>::iterator trackIT;
try{
for(noteIT = trackIT->getNoteList().begin(); noteIT != trackIT->getNoteList().end(); noteIT++){
cout << "---" << noteIT->second.getName() << endl;
}
}catch (int e){
cout << "exception #" << e << endl;
}
我想接下来做的就是重复每个Track
的Notes
。但从这部分开始,所有输出都停止。所以我只能看到第一首曲目的名字。之后的任何cout都没有显示,编译器也没有给我任何错误。即使try catch块内COUT不工作..
vector<Track>::iterator trackIT;
multimap<long, Note>::iterator noteIT;
for(trackIT = this->playlist.getTracklist().begin(); trackIT < this->playlist.getTracklist().end(); trackIT++){
cout << trackIT->getTrackName() << endl;
for(noteIT = trackIT->getNoteList().begin(); noteIT != trackIT->getNoteList().end(); noteIT++){
cout << "---" << noteIT->second.getName() << endl;
}
}
cout << "random cout that is NOT shown" << endl; // this part doesn't show up in console either
而且,在我的田径类中的方法,我使用添加的注释对象是这样的:
void Track::addNote(Note ¬e) {
long key = 1000009;
this->noteList.insert(make_pair(key, note));
}
// I'm adding the notes to the track like this:
Note note1(440, 100, 8, 1, 1);
note1.setName("note1");
synthTrack.addNote(note1);
任何想法为什么迭代器不会工作?
'Note'的拷贝构造函数可能有问题。 - 类型签名不应该是'void Track :: addNote(const Note&note)'?或'void Track :: addNote(Note && note)'。 – leftaroundabout 2012-04-18 15:40:14
'this-> curMsr'的价值是什么? – 2012-04-18 15:46:10
您是否检查'notesIT'实际上是否在'trackIT-> end()'? 'this-> curMsr'的价值是什么? – Grizzly 2012-04-18 15:46:19