我發現在調用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