通过函数指针调用函数时出错(错误C2064)

Error (error C2064) while calling function through function pointer

本文关键字:函数 错误 C2064 出错 指针 调用      更新时间:2023-10-16

我收到的确切错误是:

error C2064: term does not evaluate to a function taking 0 arguments

我正在尝试创建一个基本的逻辑门模拟工具。这只是基本逻辑的一部分,这是我的第一个这样规模的项目。我在下面包含的是一个门类的代码,一个AND门类将继承这个基类的属性。我的错误发生在函数指针调用处。

class gate
{
    protected:
    short int A,B;//These variables represent the two inputs to the Gate.
    public:
    short int R;//This variable stores the result of the Gate
    gate *input_1, *input_2;//Pointers to Inputs
    void (gate::*operationPtr)();
    void doAND()//Does AND operation
    {
        R=A&&B;
        operationPtr=&gate::doAND;
    }
    short int getResult()
    {
        operationPtr();//ERROR OCCURS HERE
        return R;
    }
};

operationPtr是指向成员函数的指针,不是指向函数的指针这意味着要取消对它的引用,还必须提供一个调用函数的对象。你可能是这个意思:

short int getResult()
{
    (this->*operationPtr)();
    return R;
}