开发者

list of pointers in c++

开发者 https://www.devze.com 2022-12-26 08:22 出处:网络
What i want to do is for (list<cPacket *>::iterator i = cache.begin(); i != cache.end(); i++){ if( st开发者_开发技巧rcmp(i->getName(),id) == 0 ){

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
0

精彩评论

暂无评论...
验证码 换一张
取 消