I’ve been trying to create a runnable class in order to interface multi-threaded classes just like java-folks do. But I can’t seem to use _beginthread with the virtual function run.
I’m getting the following error:
‘beginthread’ : cannot convert parameter 1
from ‘void (_cdecl Runnable::* )(void *)’ to ‘void (__cdecl *)(void *)’
#include "CriticalSection.h"
#include <stdio.h>
#include <conio.h>
#include <process.h>
class Runnable{
private:
Runnable() { _beginthread(&Runnable::Run,0,(void*)0); }
~Runnable();
virtual void __cdecl Run ( void* ) = 0;
};
int main(){
//CriticalSection crt;
//ErrorHandler err;
//LockSection lc(&crt,&err);
while(!kbhit());
return 0;
}
You need the function to be passed to
_beginthreadto bestatic.I suggest you read this article by Herb Sutter and try to implement the Active Object Pattern.