函数指针传递问题
函数指针声明
typedef void (*funCB)(void);
函数定义
bool sync(funCB cb = NULL);
void Step(void);
函数调用
sync(&CcomTestDlg::Step);
无法从“void (__thiscall CcomTestDlg::* )(void)”转换为“funCB” 函数指针
[解决办法]
#include "stdafx.h"
#include <iostream>
using namespace std;
typedef void (*funCB)(void);
bool sync(funCB cb = NULL);
void Step(void);
void Step(void)
{
cout<<"Step"<<endl;
}
bool sync(funCB cb )
{
cout<<"sync"<<endl;
return true;
}
int _tmain(int argc, _TCHAR* argv[])
{
funCB pb = Step;//楼主这么调用
sync(pb);
system("pause");
return 0;
}
[解决办法]
void pClassFun(void* this,void* pFun,void param 0 ... void param n);
{
__asm
{
push n
....
push 0
lea ecx, [this]
call pFun
}
}
手头没有编译器,上面的代码大概给你个思路。
希望你能看懂。