class Secure {
private:
int seconds;
bool isRUNNING;
public:
Secure(int seconds) {
this->seconds = seconds;
isRUNNING = true;
}
void doSCAN() {
while (isRUNNING) {
//SCAN_CODE_HERE
}
}
}
void PROTECT() {
Secure secure = new Secure(5);
DWORD sHandle = NULL;
::CreateThread(NULL, NULL, &secure->doSCAN, NULL, 0, NULL);
}
int main() {
PROTECT();
while (true) {
//DO_PROGRAM
}
return 0;
}
ERROR:
error C2276: '&' : illegal operation on bound member function expression
I read that due to explicit casting, threads cannot be created within a class.
I'm trying to thread a scanning system to relieve stress on my main program/module, rather than having the scanner stunt their performance.
CreateThread is part of a C api. You cannot pass a pointer to a C++ member function to CreateThread (and if you could, your syntax would be wrong as indicated by the error message.)
Pointer to member functions are sometimes larger than C function pointers (as well as having different calling conventions) and there is no guarantee it will fit into a void pointer.
Pointer to member functions are sometimes larger than C function pointers (as well as having different calling conventions) and there is no guarantee it will fit into a void pointer.
Pointer to member functions are sometimes larger than C function pointers (as well as having different calling conventions) and there is no guarantee it will fit into a void pointer.
Note that if the only barrier to using a member function pointer was the signature, feeding one to CreateThread would be trivial, since a pointer-to-class will fit into a void pointer, but both calling convention and pointer sizes may vary for member functions.