Reputation: 29
What do I need to write (in "?!?!?!") if I want to printing all the names by the iterator iter? the class have only name, c
//the code
class H {
string name;
public :
H (string n="WWW"): name(n){}
string getName()const{return name;};
};
void main ()
{
H h1("HHH");
H h2;
list<H*> HH;
list<H*>::iterator iter=HH.begin();
HH.insert(iter,h1);
HH.insert(iter,h2);
for (; iter != HH.end(); iter++)
cout<<iter //?!?!?!
}
Upvotes: 0
Views: 2547
Reputation: 279455
std::cout << (*iter)->getName() << '\n';
or whatever separator you want other than newline.
Also, your insert
lines are wrong because h1
and h2
have type H
, whereas the container is of H*
.
Upvotes: 1