Solved

Help with iterators

Posted on 2003-10-22
4
278 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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

929 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now