首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

函数指针传递有关问题

2013-09-14 
函数指针传递问题函数指针声明typedef void (*funCB)(void)函数定义bool sync(funCB cb NULL)void Ste

函数指针传递问题
函数指针声明
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
  }
}

手头没有编译器,上面的代码大概给你个思路。
希望你能看懂。

热点排行