C++ 作类型转换的时候遇到问题
#include <stdio.h>
static int foo()
{
printf("hello/n");
return 0;
}
typedef int fnc_t();
int main(int argc, char* argv[])
{
void* fv = (fnc_t*)foo;
fnc_t* fnc = reinterpret_cast<fnc_t*>(fv); // illegal under GNU/linux
fnc();
return 0;
}
===gcc 编译结果========================
gcc test.cpp
test.cpp: In function `int main(int, char**)':
test.cpp:16: error: invalid conversion from `int (*)()' to `void*'
test.cpp:18: error: ISO C++ forbids casting between pointer-to-function and pointer-to-object
VC6 可以。。。 有空深究一下。