我正在尝试将类的成员函数作为参数(函数指针)传递,我的代码如下
我收到错误消息“调用时类型参数与参数不兼容
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;
}
'''