从结构调用C成员函数指针

我已经找到了有关调用C成员函数指针和在结构中调用指针的信息,但我需要调用一个存在于结构内部的成员函数指针,并且我无法使语法正确.我在MyClass类的方法中有以下代码段:
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);')

移动这些括号导致语法错误,建议使用.*或 – > *这两种情况都不起作用.有谁知道正确的语法?

解决方法

使用:
(this->*functionMap[0].command)(x,y);

经过测试和编译;)

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...