关于_beginthread 传递参数
int index = 1;//要把这个传递到_beginthread要怎么做?
_beginthread(thrdFunc, 0, (void*)index);//这样会报错 cannot convert parameter 1 from 'unsigned int (void *) ' to 'void (__cdecl *)(void *) '
网上说把它定义成一个结构体,我这样
struct args {
int index;
}
args arg;
arg.index = 1;
_beginthread(thrdFunc, 0, (void*)arg);//这样会还是报错 cannot convert from 'struct args ' to 'void * '
究竟应该怎么改呢
[解决办法]
_beginthread(thrdFunc, 0, (void*)index);//这样会报错 cannot convert parameter 1 from 'unsigned int (void *) ' to 'void (__cdecl *)(void *) '
这个错误是函数定义的原型不对。
_beginthread(thrdFunc, 0, (void*)arg);//这样会还是报错 cannot convert from 'struct args ' to 'void * '
究竟应该怎么改呢
(void*)arg 中的 arg前面缺少地址符号 应该是 (void*)&arg .