C++ Function Callbacks: Cannot convert from a member function to a function signature

后端 未结 6 510
盖世英雄少女心
盖世英雄少女心 2020-11-29 12:22

I\'m using a 3rd party library that allows me to register callbacks for certain events. The register function looks something like this. It uses the Callback signature.

6条回答
  •  自闭症患者
    2020-11-29 13:12

    Member functions are not convertible to the normal functions for its own good reasons. If your design allows, then make MyStruct::myCallback() a static member method and the code should work fine.

    struct MyStruct {
      ...
      static int myCallback(std::string str);
      ^^^^^^
    };
    

提交回复
热议问题