定义(Core.h):
static int (*foolink)(int*, char*, key*, key*);
也在 Core.cpp 中重新定义。此代码导致错误:
foolink = this->step;
错误:
Engine/Core.cpp:31: error: argument of type 'int (Core::)(int*, char*, key*, key*)' does not match 'int (*)(int*, char*, key*, key*)'
指针使用:
(*foolink)(NULL, NULL, NULL, NULL);
怎么了?请帮助我!
最佳答案
在C++程序中,大多数函数都是成员函数;也就是说,它们是一个类的一部分。不允许使用普通的函数指针指向成员函数;相反,您必须使用成员函数指针。
在您的情况下,您可以将其定义为
v you have to name the class here
int (YourClass::*foolink)(int*, char*, key*, key*);
foolink = &YourClass::step;
// This is how you can call the function via member function pointer
YourClass object, *pObject = &object;
// One way is to envoke the function from object
(object.*foolink)(...);
// The other way is from pointer to object
(pObject->*foolink)(...);
C++ 常见问题解答:
关于c++ - 类初始化时如何用非静态类函数初始化静态函数指针?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5853052/