Solved

Help with iterators

Posted on 2003-10-22
4
281 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 250 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

Suggested Solutions

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

710 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