To pass a pointer to a member function

后端 未结 4 783
闹比i
闹比i 2021-01-13 03:51

I have an class with instance functions (or methods?). From within an instance, I try to pass pointers to those functions to a library. The library expects static functions

4条回答
  •  太阳男子
    2021-01-13 04:57

    you should have a static method and an instance (possibly static) to call a member function of instance from static function

    Something like this:

    //static method
    void MyClass::myCallback()
    {
        static MyClass instance; //or you can store your in instance in some Singleton, or
        //possibly create a temporary
        instance.nonStaticMethod();
    }
    

提交回复
热议问题