16,471
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <string>
#include <map>
using namespace std;
class CTest
{
public:
typedef bool (__stdcall CTest::*PCFUNC)(void);
map<string, PCFUNC> m_mapCall;
bool __stdcall func()
{
cout<<"CTest::func"<<endl;
return true;
}
void init()
{
#define DECLARE_PCSUITE_CALLMETHOD(name, func) m_mapCall[##name] = &CTest::func;
DECLARE_PCSUITE_CALLMETHOD("func", func)
}
void call(string funcname)
{
if(m_mapCall.end() != m_mapCall.find(funcname))
{
(this->*m_mapCall[funcname])();
}
}
};
int _tmain(int argc, _TCHAR* argv[])
{
CTest obj;
obj.init();
obj.call("func");
system("pause");
return 0;
}
#include "stdafx.h"
#include <windows.h>
#include <iostream>
using namespace std;
typedef void (__stdcall *PFUNC)(void);
void __stdcall callback(void)
{
cout<<"callback"<<endl;
}
void TestCallBack(int pfunc)
{
(*(PFUNC)pfunc)();
}
int _tmain(int argc, _TCHAR* argv[])
{
TestCallBack((int)callback);
system("pause");
return 0;
}
#include "stdafx.h"
#include <windows.h>
#include <iostream>
using namespace std;
void __stdcall callback(void)
{
cout<<"callback"<<endl;
}
void TestCallBack(void (__stdcall *pfunc)(void))
{
pfunc();
}
int _tmain(int argc, _TCHAR* argv[])
{
TestCallBack(callback);
system("pause");
return 0;
}