Iterators

D

Dario Kampkaspar

'kay, I know this is a newbie-question. I didn't work into iterators
too deeply, so I'll ask you. Got a code from a friend containing sth.
like this:

typedef vector<class Aktion> abtable;

Aktion* gib_aktion (int id){
abtable::iterator aktion;

[some for-loop begin to end]
if(aktion->gib_id() == pers_id) return aktion;
}

Compiling this will give me the error
"cannot conver '__gnu_cxx::__normal_iterator<Aktion*,
std::vector<Aktion, std::allocator<Aktion> > >' to 'Aktion*'
in return"

I understand, that accessing the iterator will dereferece it (so,
aktion->gib_id() accesses a function of class Aktion contained within
the vector). But, how will I get this to work correctly - how can I
get the pointer to Aktion?

Thx in advance, greetings

Dario
 
J

Jeff Schwab

Dario said:
'kay, I know this is a newbie-question. I didn't work into iterators
too deeply, so I'll ask you. Got a code from a friend containing sth.
like this:

typedef vector<class Aktion> abtable;

Aktion* gib_aktion (int id){
abtable::iterator aktion;

[some for-loop begin to end]
if(aktion->gib_id() == pers_id) return aktion;

if(aktion->gib_id() == pers_id) return &*aktion;
 
D

Dario Kampkaspar

Dario said:
'kay, I know this is a newbie-question. I didn't work into iterators
too deeply, so I'll ask you. Got a code from a friend containing sth.
like this:

typedef vector<class Aktion> abtable;

Aktion* gib_aktion (int id){
abtable::iterator aktion;

[some for-loop begin to end]
if(aktion->gib_id() == pers_id) return aktion;

if(aktion->gib_id() == pers_id) return &*aktion;

Thanks for the fast answer! Helped me a lot!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,839
Latest member
MartinaBur

Latest Threads

Top