使用std :: list :: iterator時,編譯器會提供一條消息「錯誤:不允許類限定名稱,我不確定是什麼問題?在錯誤:不允許類限定名稱
#include <iostream>
#include <list>
using std::cout;
using std::endl;
using std::list;
using std::list<int>::iterator;
int main()
{
list<int> listObject;
for (int i = 1; i <= 3; i++)
listObject.push_back(i);
cout << "List contains:\n";
iterator iter;
for (iter = listObject.begin(); iter != listObject.end(); iter++)
cout << *iter << " ";
cout << endl;
cout << "Setting all entries to 0:\n";
for (iter = listObject.begin(); iter != listObject.end(); iter++)
*iter = 0;
cout << "List now contains:\n";
for (iter = listObject.begin(); iter != listObject.end(); iter++)
cout << *iter << " ";
cout << endl;
return 0;
}
一般來說,當任務有關錯誤的問題時,發佈錯誤文本非常有幫助 – aruisdante