将函数指针作为参数传递时出错

时间:2019-12-05 09:12:45

标签: c++

我正在尝试将类的成员函数作为参数(函数指针)传递,我的代码如下

我收到错误消息“调用时类型参数与参数不兼容

testA-> SetMasterVariableCalback(GetMasterVariable);

'''

class  __declspec(dllexport) TestA
{
    public:
            typedef int(* MasterVariableCallbackType)(string);
            void SetMasterVariableCalback(MasterVariableCallbackType Function);
            MasterVariableCallbackType MasterVariableCallbackFunction;

}

void TestA::SetMasterVariableCalback(MasterVariableCallbackType Function)
{
    try
    {
        MasterVariableCallbackFunction = (MasterVariableCallbackType)(Function);
    }
    catch (const std::exception&)
    {
    }
}
'''

'''
#include "TeatA"

class  __declspec(dllexport) TestB
{
    public:
        TestA* testA
        TestB();
        int GetMasterVariable(string name);
}


TestB::TestB()
{
    testA->SetMasterVariableCalback(GetMasterVariable);
}

int CZVNode::GetMasterVariable(string name)
{
    return 0;
}
'''

0 个答案:

没有答案