我很努力地用STL列表來保存我的「對象」對象的指針。C++ STL:列表指針 - 迭代器無法訪問?
我宣佈:
list<Object*> objectlist;
,並通過插入:
this->objectlist.push_back(new Object(address,value,profit));
,並試圖重複像地圖及其他:
list<Object*>::iterator iter;
iter = this->objectlist.begin();
while(iter != this->objectlist.end())
{
iter->print();
}
其中的print()是一個公共方法對象類;
這裏有什麼問題嗎?
我無法通過迭代器訪問列表中的對象?
是的,你的迭代是** **不是一個指向對象類型,而是一個迭代器。此外_不要忘記你的**增量** _或者你將有一個無限循環。 – crashmstr