Learn how to a build a cloud-first strategyRegister Now


Iterator compile error

Posted on 2011-10-31
Medium Priority
Last Modified: 2012-05-12
Hi I am getting a compile error in the assignment.
It is complaining about cannot convert 'const std::pair<const int, void(*)()> to void(*)()

What could be wrong here.

typedef void (*Callback)();
typedef std::map<int, Callback>  listenerMap_t;
typedef std::map<int, Callback>::const_iterator listenerIter_t;

 Callback cb;

    listenerIter_t listenerIter = listenerMap.find(attr);
    if(listenerIter != listenerMap.end() )
        cb = *listenerIter;   <--- error


Open in new window

Question by:ambuli
  • 2
LVL 40

Accepted Solution

evilrix earned 2000 total points
ID: 37058074

cb = listenerIter->second;

Author Comment

ID: 37058081
Thank you.  

Author Comment

ID: 37058100
Hi evlrix,
Why it has to be ->second ?( I admit I am not very familar with STD.  I am still learning).  Thx.
LVL 86

Expert Comment

ID: 37058217
That was my fault in your last Q - 'find()' returns a 'pair', thus you need 'second' here. Full credit to evilrix for spotting that, no points for this comment please ;o)

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

810 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