pavlos
pavlos

Reputation: 31

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 function of the class cPacket, But it does not work, i tries also i.operator->()->getName(), and again nothing.

Can anybody help me?

Upvotes: 2

Views: 7471

Answers (3)

sp3tsnaz
sp3tsnaz

Reputation: 506

replace

list<cPacket *>::iterator i

with

list<cPacket>*::iterator i

Upvotes: -3

Alexander Gessler
Alexander Gessler

Reputation: 46607

*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()

Upvotes: 6

Niki Yoshiuchi
Niki Yoshiuchi

Reputation: 17561

(*i)->getName()

is what you are looking for.

Upvotes: 8

Related Questions