How do you pass a non-static function as a callback?

后端 未结 3 482
说谎
说谎 2021-01-25 19:39

I\'m currently working with Qt and a graphics engine and during the init of the QGLWidget instance I need to pass a few function pointers to my engine.

The function look

相关标签:
3条回答
  • 2021-01-25 20:03

    You can't. That's what std::function exists for. You need to either change your interface to use std::function, get lucky and find some kind of void* context argument, or give up.

    0 讨论(0)
  • 2021-01-25 20:03

    This is because it is impossible to tell(from the compiler's POV) which this pointer should be pass into that function when that callback is called. If you really really want to pass in a pointer, you'll have to use assembly.

    0 讨论(0)
  • 2021-01-25 20:17

    See this question, I think it is pretty much what you want to do:

    How do I implement a callback in C++?

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