Creating a Thread with param a class

G

Guest

Hi
i am trying to create a Thread using _beginthread that will access data in a class but i keep getting a C2664: '_beginthread' : cannot convert parameter 1 from 'void (DBLR<T>&)' to 'void (__cdecl *)(void *)' with [ T=Packet *].

Anyone who can help, please do so, its driving me crazy. I know its most probably a type casting problem but i don't know what to do
Thank
/////////////////////////////////////////////////////////////code sampl
void qtest1( DBLR<Packet*>&QQQ
{
//do something using whatever instance of DBLR was passe


int main()
{
DBLR<Packet*> DBL; //DBLR template ini

_beginthread( qtest1,0, &DBL )
_endthread();
 
A

Adam Clauss

Regardless of what you are passing, the thread function has to be of the
type:
void qtest1(void* param);
You can't "explicity" put your class there.

Instead, pass it as a void* and then cast it back into a pointer to your
class inside the function.
Ex:
void qtest1(void* param)
{
MyClass* myParam = (MyClass*)param;

....
}

int main()
{
MyClass* x = new MyClass();
_beginthread(qtest1,0,x);
...
}

HTH
--
Adam Clauss
(e-mail address removed)
Dim said:
Hi,
i am trying to create a Thread using _beginthread that will access data in
a class but i keep getting a C2664: '_beginthread' : cannot convert
parameter 1 from 'void (DBLR said:
Anyone who can help, please do so, its driving me crazy. I know its most
probably a type casting problem but i don't know what to do.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top