Is there any way to specify a class member function as the thread procedure in calls such as beginthreadex() or CreateThread()?
Is there any way to specify a class member function as the thread procedure in calls such as beginthreadex() or CreateThread()?
"Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C
Yes, but they must be static member functions............Originally posted by johnnie2
Is there any way to specify a class member function as the thread procedure in calls such as beginthreadex() or CreateThread()?
Code:#include <iostream> #include <string> #include <windows.h> class foobar{ public: static DWORD WINAPI ThreadProc(LPVOID); }; DWORD WINAPI foobar::ThreadProc(LPVOID lpv){ std::cout << static_cast<char*>(lpv); return 0; } int main(void){ DWORD dwDummy; HANDLE hHand; char str[] = "Hello World"; hHand = CreateThread(0,0,&foobar::ThreadProc, static_cast<LPVOID>(str),0,&dwDummy); WaitForSingleObject(hHand,INFINITE); };
Thanks for the response. I'm guessing there is absolutely no way to accomplish this with non-static member functions?
"Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C
Right.
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }