Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Help with iterators

Posted on 2003-10-22
4
Medium Priority
?
284 Views
Last Modified: 2010-04-02
Hi.  How do I access a member of an Associate object held in lista using an iterator like below?


    typedef list<Associate>::iterator iter;

 void display(list<Associate>& lista)
{
    int i=1;
    for (iter through=lista.begin(); through!=lista.end(); ++through)
     {
          cout << i << ". number is:" <<?????????<< "\t" << endl;
      }
}

I can't find anything in my books about it i've tried replaceing the ???? with lista.name.... lista(name).... lista(through.name) and several other things but I can't figure it out.

This is just an example i'm trying to get to work so that I can write other functions like search using iterators but I can't figure out how to access the memebers of the Associate held in list.
0
Comment
Question by:RiMZ
  • 2
4 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 9597811
cout << i << ". number is:" << (*iter).GetNumber() << "\t" << endl;

Assuming that GetNumber() is function of Associate class.
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 1000 total points
ID: 9597815
Sorry, correction:

cout << i << ". number is:" << (*through).GetNumber() << "\t" << endl;

0
 
LVL 1

Expert Comment

by:Hoegje
ID: 9597852
Or somthing similar (and maybe more used) :

cout << i << ". number is:" << through->GetNumber() << "\t" << endl;

Always assuming GetnNumber is a member function of Associate as Alex said..
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 9597882
Older libraries only support AlexFM's approach.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question