Iterator compile error

Posted on 2011-10-31
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
    LVL 39

    Accepted Solution


    cb = listenerIter->second;

    Author Comment

    Thank you.  

    Author Comment

    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

    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

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    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…
    Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
    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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

    755 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

    20 Experts available now in Live!

    Get 1:1 Help Now