下面的代码:
#include <iostream>
#include <list>
class A
{
public:
void printHello(){std::cout << "hello";}
};
int main(int argc, char *argv)
{
std::list<A*> lista;
lista.push_back(new A());
for(std::list<A*>::iterator it=lista.begin();it!=lista.end();++it)
{
//how to get to printHello method?
//it doesn't work
it->printHello();
}
return 0;
}
此代码不起作用。我的问题是如何通过迭代器获取方法'printHello'?谢谢。