boost::bind & boost::function pointers to overloaded or templated member functions

前端 未结 2 1440
感动是毒
感动是毒 2020-12-14 20:20

I have a callback mechanism, the classes involved are:

class App
{
    void onEvent(const MyEvent& event);
    void onEvent(const MyOtherEvent& event         


        
相关标签:
2条回答
  • 2020-12-14 20:56

    I think you need to disambiguate the address of the overloaded function. You can do this by explicitly casting the function pointer to the one with the correct parameters.

    boost::bind( static_cast<void (App::*)( MyEvent& )>(&App::OnEvent) , this, _1);
    

    Similar problem + solution on gamedev.net

    0 讨论(0)
  • 2020-12-14 21:09

    You are going to want to do

    boost::function<void (const MyEvent&)> g = boost::bind(&App::OnEvent, this, _1);
    

    You should be able to do g(event); with that

    I am not quite sure what you are trying to accomplish here, but that should solve one of your problems for now.

    0 讨论(0)
提交回复
热议问题