C++ Using Class Method as a Function Pointer Type

后端 未结 3 511
庸人自扰
庸人自扰 2020-11-29 11:53

In a C lib, there is a function waiting a function pointer such that:

lasvm_kcache_t* lasvm_kcache_create(lasvm_kernel_t kernelfunc, void *closure)
         


        
3条回答
  •  鱼传尺愫
    2020-11-29 12:23

    Every C++ member function has an implicit, hidden, first parameter, this.

    So the method double cls_lasvm::kernel(int i, int j, void* kparam) is really: double cls_lasvm::kernel(cls_lasvm* this, int i, int j, void* kparam), and it is inappropriate/impossible to use it as a function-pointer parameter.

    To make progress, convert your method to be a static-member-method. That will remove the this pointer. You may still have other issues to overcome, but that is a good start.

提交回复
热议问题