Acessing functions in a map element

I'm attempting to access and element from the iterator returned by the STL map method Begin().

I did the following:itor =
M.begin();
(*itor).PrintInfo();

and the PrintInfo is *DEFINATELY* a function that in the class which the map is created of.  The compiler returns:

error C2039: 'PrintInfo' : is not a member of 'pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class genericcustomerclass>'

I have tried accessing it using the -> operator with no luck.  COuld someone *PLEASE* help me out.  I'm quite frustrated as everything I read seems to lead me to believe this should work just fine.  Thanks.

      
LVL 1
timberbtAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
chensuConnect With a Mentor Commented:
(*itor).second.PrintInfo();
0
 
timberbtAuthor Commented:
btw
itor was declared as follows:

customerlist::iterator itor;


and customerlist is:

typedef map<string,genericcustomerclass> customerlist;


and the void PrintAll() is a public function of the genericcustomerclass

(forgive the names, i was toying with a bunch of different ideas)
0
 
chensuCommented:
If you want to access the string, use (*itor).first.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
timberbtAuthor Commented:
Wonderful!  COuld you explain what the .first and .second are doing?  And why the function is accessed via the .second?

None of my books seem to mention this, I'll accept the answer regardless, but I'd appreciate a better understanding.  Thanks!!!!
0
 
chensuCommented:
Take a look at the map template class. A map holds a set of ordered key/value pairs and the data type of each element is

typedef pair<const Key, T> value_type;

first and second are two member variables of the pair template struct.

template<class T, class U>
    struct pair {
    typedef T first_type;
    typedef U second_type
    T first;
    U second;
    pair();
    pair(const T& x, const U& y);
    template<class V, class W>
        pair(const pair<V, W>& pr);
    };
0
 
timberbtAuthor Commented:
Wonderful!  That makes perfect sense now, thanks again!
0
 
timberbtAuthor Commented:
did that give you 20 or 200 points?  I had this originally as a 200 point question but now it shows "20" at the top.  Don't want to rip you off or anything.
0
 
chensuCommented:
Thank you, I got 200 points x grade A. Once an answer is accepted, the points of a question become 10% for others to view.
0
 
timberbtAuthor Commented:
ah, okay just wanted to make sure.  Thanks again.  
0
All Courses

From novice to tech pro — start learning today.