How do I implement a callback in C++?

前端 未结 6 2223
野性不改
野性不改 2020-12-05 19:52

I want to implement a class in c++ that has a callback.

So I think I need a method that has 2 arguments:

  • the target object. (let\'s say *myObj)
  • <
6条回答
  •  感情败类
    2020-12-05 20:20

    In C++, pointers to class methods are hardly used. The fact that you called in - it is delegates and their use is not recommended. Instead of them, you must use virtual functions and abstract classes. However, C++ would not have been so fond of me, if it not supported completely different concepts of programming. If you still want delegates, you should look towards "boost functional" (part of C + +0 x), it allows pointers to methods of classes regardless of the class name. Besides, in C++ Builder has type __closure - implementation of a delegate at the level of the compiler.

    P.S. Sorry for bad English...

提交回复
热议问题