<分区>
我试图用一个函数指针调用一个函数,其中函数指针是一个类成员。
我简化了代码以仅展示问题,但是原始代码中的 foo()
函数已经写好了,所以我无法更改它。
(在我的实际代码中,foo
来自 GLFW(glfwSetKeyCallback
),A
是输入处理程序类。)
代码是:
#include <iostream>
// this four line can not be changed
typedef void(*fptr)(int);
void foo(fptr f) {
f(0);
}
void testOutA(int i) {
}
class A {
public:
void testInA(int i) {
}
};
int main()
{
foo(testOutA); // works fine as it should be
A * a = new A();
foo(a->testInA); // ERROR
return 0;
}
编译错误信息为:
ERROR: error C3867: 'A::testInA': non-standard syntax; use '&' to create a pointer to member