Solved

Help with iterators

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 clear a vector as well as how to detect empty vectors in C++.

756 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