我試圖插入一個地圖的內容到另一個。下面是代碼:爲什麼在插入地圖時遇到seg錯誤?
std::map<std::string, int> Student::getGrades() const;
...
for(set<Student*, Cmp>::const_iterator it = s.begin(); it!=s.end(); ++it)
{
grades.clear();
grades.insert((*it)->getGrades().begin(), (*it)->getGrades().end());
for(map<string, int>::const_iterator itt = grades.begin(); itt!=grades.end(); ++itt)
{
if(itt->first == course && itt->second >= score1 && itt->second <= score2)
(*it)->display(cout);
}
}
s是一組包含指向學生對象和每個學生對象具有getGrades()方法返回的地圖。我試圖找到與我從文件中讀入的成績相匹配的成績,並打印與這些成績對應的記錄。但是,插入方法給了我一個seg故障。有什麼建議麼?
你可以顯示'Student :: getGrades()'的聲明嗎? – alexisdm 2012-04-09 03:16:43