typedef struct{int hash;
void* func
}NativeMethod;
Class Demo{
publuc: NativeMethod nativeMethod[];
Demo();
int exc();}
初始化时候
Demo:Demo()
{
nativeMethod[0].int=1;
nativeMethod[0].func=(void*)exc;
}
为什么最后一行有不匹配的问题
void* func
}NativeMethod;
Class Demo{
publuc: NativeMethod nativeMethod[];
Demo();
int exc();}
初始化时候
Demo:Demo()
{
nativeMethod[0].int=1;
nativeMethod[0].func=(void*)exc;
}
为什么最后一行有不匹配的问题
Demo::Demo()
{
nativeMethod[0].hash=1;
nativeMethod[0].func=(void*)exc();
}吧,你再试试,我上次也遇到类似问题。我没有解决得了,我是要将int型转换成void型。不知为什么,不可以。
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
void *f;
f=(void*)i;
}int i()
{
return 0;
}
这样是正确的!
还有你的应该是nativeMethod[0].hash=1;吧
typedef struct
{
int hash;
void (* func);
}NativeMethod;class Demo
{
public:
Demo();
~Demo();
NativeMethod nativeMethod[10];
//数组应该指定大小(我用的是VC6,不知道是不是别的编译器没有这个要求:))
static int Exec()
{
return 0;
};
};Demo::Demo()
{
nativeMethod[0].hash=0;
nativeMethod[0].func=(void (*))Exec;
}Demo::~Demo()
{
}如果func不是一个函数指针的话,
应该将
nativeMethod[0].func=(void *)Exec;
改为
nativeMethod[0].func=(void *)Exec();//把整型返回值转换为一个指针另,不能把int 转为 void