Lef*_*ler 2 c++ iterator vector
我创建了一个指针向量
vector<Person*> *personVec = new vector<Person*>();
Run Code Online (Sandbox Code Playgroud)
人包含:
getName();
getAge();
Run Code Online (Sandbox Code Playgroud)
如果我尝试使用迭代器它不起作用..这是我如何使用它:
vector<Person>::iterator it;
for(it = personVec->begin() ;
it != personVec->end() ;
++it)
{
cout << it->getName() << endl;
}
Run Code Online (Sandbox Code Playgroud)
我尝试过,vector<Person*>::iterator it;但也没有运气.
谢谢.
Cis*_*one 11
迭代器需要与容器的类型相同:
vector<Person>::iterator it;
Run Code Online (Sandbox Code Playgroud)
应该:
vector<Person*>::iterator it;
Run Code Online (Sandbox Code Playgroud)