To pass a pointer to a member function

后端 未结 4 816
闹比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:40

    In short, you can't. C++ member functions are actually 'linked' to the instance of the object. On the lower level, they have one extra parameter, which is actually the pointer to the instance of this object.

    So, you have to use static function, and, since glut wouldn't let you to pass a parameter which would identify the current instance, you will have to come up with some workaround. The simplest workaround would be to use static members. If your GlutController is singleton (and I think it is), you'll be fine.

提交回复
热议问题