New thread created in class problems

Having problems trying to figure this out. New to multithread programming.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Game
{
HANDLE hcol[7];
unsigned int WINAPI find(void *);
int threadhandler(square temp[6][7], bool turn, int level, int &minmax, int lex, int derk);
...
};

int Game::threadhandler(square temp[6][7], bool turn, int level, int &minmax, int lex, int derk)
{
hcol[0] = (HANDLE)_beginthreadex (NULL, 0, &Game::find, efa, 0, NULL);
...
}

unsigned int WINAPI Game::find(void *arg)
{
...
}


The problem is here:hcol[0] = (HANDLE)_beginthreadex (NULL, 0, &Game::find, efa, 0, NULL);

I get an C2664 error:
'_beginthreadex': cannot convert parameter 3 from 'unsigned int(_stdcall Games::*)(void*)' to 'unsigned int(_stdcall*)(void*)'

Any help would be greatly appreciated.
There is a huge difference between global functions and member functions. That is because member functions are implicitly passed one argument (this). You have to make find static. Depending on contents of find, you may have to make more changes.
in this case unsigned int WINAPI Game::find(void *arg) must be static
you can pass pointer this to static method, then you can call non static members in onther thread.
square temp[6][7] - OMFG!
Topic archived. No new replies allowed.