C++ g++;和Visual Studio
好的,这样做:C++ g++;和Visual Studio,c++,visual-studio-2008,pointers,methods,g++,C++,Visual Studio 2008,Pointers,Methods,G++,好的,这样做: methodPtrTest.cpp:14: warning: converting from ‘void (Test::*)()’ to ‘void (*)(void*)’ void threadMethod(void*ptr){ 静态_cast(ptr)->testMethod(); } ThreadPtr-ThreadPtr=&threadMethod; 这样,您处理的是一个实函数,而不是PMF。您不能在函数指针和PMF之间转换。只是不。那演员阵容很危险,你不应该想这样做
methodPtrTest.cpp:14: warning: converting from ‘void (Test::*)()’ to ‘void (*)(void*)’
void threadMethod(void*ptr){
静态_cast(ptr)->testMethod();
}
ThreadPtr-ThreadPtr=&threadMethod;
这样,您处理的是一个实函数,而不是PMF。您不能在函数指针和PMF之间转换。只是不。那演员阵容很危险,你不应该想这样做。你到底想解决什么问题?我只是想快速地将一些线程功能破解到一个测试对象中。我并不过分担心安全性,我只是希望编译器不要妨碍我。@Gearoid:至少让你的
testMethod
静态。那么至少您没有在函数指针和PMF之间进行强制转换,或者使用正确的签名生成一个短函数:void runmemberfn(void*){Test().testMethod();}
。
methodPtrTest.cpp:14: warning: converting from ‘void (Test::*)()’ to ‘void (*)(void*)’
void threadMethod(void* ptr) {
static_cast<Test*>(ptr)->testMethod();
}
ThreadPtr threadPtr = &threadMethod;