64,636
社区成员
发帖
与我相关
我的任务
分享
void * FunctionA()
{
return NULL;
}
int _tmain(int argc, _TCHAR* argv[])
{
void * pPtr;
void (*pFunc)(int);
pPtr = FunctionA();
pFunc = pPtr;//编译时这一行报错误:error C2440: “=” : 无法从“void *”转换为“void (__cdecl *)(int)”
//从“void*”到指向非“void”的指针的转换要求显式类型转换
return 0;
}
#include <iostream>
using namespace std;
void * FunctionA()
{
cout<<"success!";
return 0;
}
int main()
{
void * pPtr;
void *(*pFunc)();
pPtr = FunctionA; //这里可以把函数指针传递个void*;
pFunc = static_cast<void*(*)(void)>(pPtr);//然后将指针还原成函数指针,就行了。
pFunc();
system("pause");
return 0;
}