Click to See Complete Forum and Search --> : CreateThread compiler problem


venAdder
May 4th, 2006, 11:57 AM
Hi,

I have following code:

UINT CTCPServer::Init( UINT portNum )
{

....

CreateThread(NULL, 0,&(CTCPServer::ClientThread),
(LPVOID)clientSocket,
0,
NULL);

}

void CTCPServer::ClientThread( LPVOID id)
{

}

I get fgollowing compiler error-

error C2276: '&' : illegal operation on bound member function expression


umm what am i doign wrong ehre?

any help please.

wildfrog
May 4th, 2006, 12:06 PM
The member function used as 'ThreadProc' must be static.

static UINT CTCPServer::Init( UINT portNum )
{
//...

- petter

venAdder
May 4th, 2006, 12:12 PM
but saying it is static would mean i won't be able to start more then one thread on that fucntion will i?

I wanna start as many threads as there are cleints who wish to conenct to server.

please correct me if am wrong.

wildfrog
May 4th, 2006, 12:28 PM
You can still start alot of threads, even if the thread proc is static.

The problem with a static member function is that you cannon use the this keyword, because the function belongs to a class, not to an instance. To get around that problem you can pass the pointer to your instance as argument to CreateThread.

Oops, I realize that I used the wrong function in my last post. What i meant was ofcourse:

static void CTCPServer::ClientThread( LPVOID id)
{

}

- petter

venAdder
May 4th, 2006, 12:36 PM
cool thnx, cna't wait to see this working

thnk you

MikeAThon
May 4th, 2006, 09:48 PM
...Oops, I realize that I used the wrong function in my last post. What i meant was ofcourse:
You were right the first time to return a UINT ( not void) :)

I think the thread function should be:

static UINT CTCPServer::ClientThread( LPVOID id)
{
return iSomeValue;
}


Mike