passing functor as function pointer

后端 未结 10 2246
旧巷少年郎
旧巷少年郎 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:30

    Hm, maybe you could write a free template function that wraps around your function-objects. If they all have the same signature, this should work. Like this (not tested):

    template
    int function_wrapper(int a, int b) {
        T function_object_instance;
    
        return funcion_object_instance( a, b );
    }
    

    This would do for all function that take two ints and return an int.

提交回复
热议问题