GCC reinterpret_cast 的问题

来源:互联网 发布:矩阵机箱 编辑:程序博客网 时间:2024/06/11 03:30

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 可以。。。 有空深究一下。

原创粉丝点击