我发现在调用C++成员函数指针和结构调用的指针信息,成员函数的指针,但我需要调用一个结构内部存在一个成员函数指针,我一直没能得到正确的语法。我在MyClass类的方法中下面的代码片段:调用C++从结构
void MyClass::run() {
struct {
int (MyClass::*command)(int a, int b);
int id;
} functionMap[] = {
{&MyClass::commandRead, 1},
{&MyClass::commandWrite, 2},
};
(functionMap[0].MyClass::*command)(x, y);
}
int MyClass::commandRead(int a, int b) {
...
}
int MyClass::commandWrite(int a, int b) {
...
}
这给了我:
error: expected unqualified-id before '*' token
error: 'command' was not declared in this scope
(referring to the line '(functionMap[0].MyClass::*command)(x, y);')
移动这些括号围绕导致语法错误使用推荐*或 - > *两者都不工作在这个情况下。有谁知道正确的语法?
http://stackoverflow.com/questions/990625/c-function-pointer-class-member-to-non-static-member-function似乎与此相关的问题。 – Rudi