passing functor as function pointer

后端 未结 10 2237
旧巷少年郎
旧巷少年郎 2020-11-29 03:52

I\'m trying to use a C library in a C++ app and have found my self in the following situation (I know my C, but I\'m fairly new to C++). On the C side I have a collection of

10条回答
  •  抹茶落季
    2020-11-29 04:38

    It depends if this is a static or instance method, if it is static then you can pass through the function as className::functionName, if it is an instance method it is fair more complicated, because you obviously need to tie to a certain instance but can't do it in the same way as you would with delegates in C# etc.

    The best way I've found of doing this is to create a holding class which is instantiated with the instance of the object as well as the function pointer, the holding class can then invoke the function directly.

提交回复
热议问题