List of pointers in C ++

What I want to do is

for (list<cPacket *>::iterator i = cache.begin(); i != cache.end(); i++){
        if( strcmp(i->getName(),id) == 0 ){
            return true;
        }
}

      

where getName

is a function of the cPacket class but it doesn't work, I also try i.operator->()->getName()

, and again nothing.

Can anyone help me?

+2


source to share


3 answers


(*i)->getName()

      



is what you are looking for.

+8


source


*i

separates the iterator. Since the data type is a list pointer to cPacket

, you need to apply an operator ->

to access its members. Brackets are required for correct evaluation:



(*i)->whatever()

      

+6


source


replace

list<cPacket *>::iterator i

      

from

list<cPacket>*::iterator i

      

-3


source







All Articles