Iterator compile error

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

Who is Participating?
evilrixConnect With a Mentor Senior Software Engineer (Avast)Commented:

cb = listenerIter->second;
ambuliAuthor Commented:
Thank you.  
ambuliAuthor Commented:
Hi evlrix,
Why it has to be ->second ?( I admit I am not very familar with STD.  I am still learning).  Thx.
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)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.