What i want to do is
for (list<cPacket *>::iterator i = cache.begin(); i != cache.end(); i++){
if( st开发者_开发技巧rcmp(i->getName(),id) == 0 ){
return true;
}
}
where getName
is function of the class cPacket, But it does not work, i tries also
i.operator->()->getName()
, and again nothing.
Can anybody help me?
(*i)->getName()
is what you are looking for.
*i
dereferences the iterator. As the data type of the list is pointer to cPacket
, you need to apply the ->
operator to access its members. Parentheses are needed for proper precendence:
(*i)->whatever()
replace
list<cPacket *>::iterator i
with
list<cPacket>*::iterator i
精彩评论