About Virtual function

S

Steven Lien

Does any one know, where i made mistake?
I was thinking to make a virtual thread execution body, so child can simply
extend it
and simply implemented it execution body. But i got a build error message

see below
----------------------------------------------------------------------------
-----------------
//ThreadGroup.cpp

#include <windows.h>
#include <process.h>

#include "threadgroup.h"

/*Start the new thread */
void GameThread::start()
{
thread_handle= _beginthread(run,0,this->thread_data_member); <- caused
error here
}
----------------------------------------------------------------------------
------------------
// threadgroup.h
class GameThread
{
public:
GameThread(PVOID param);
PVOID getThreadDataMemeber();
void start();
virtual VOID run(PVOID test)=0; <- this is function body that i leave as
virtual, look like i have to make it static
to get executed,
any clue for that?

private:
PVOID thread_data_member;
uintptr_t thread_handle;
};



----------------------------------------------------------------------------
-------------------



I used VC++ to compile above code, but it gave me below build error message

beginthread' : cannot convert parameter 1 from 'void (PVOID)' to 'void
(__cdecl *)(void *)'



Any help will be appreciated....
 
R

Rolf Magnus

Steven said:
Does any one know, where i made mistake?
I was thinking to make a virtual thread execution body, so child can
simply extend it and simply implemented it execution body. But i got
a build error message

See the FAQ at http://www.parashift.com/c++-faq-lite/, especially
question 33.2 "How do I pass a pointer-to-member-function to a signal
handler, X event callback, system call that starts a thread/task, etc?"
Please always check the FAQ before posting here.
 

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

Members online

Forum statistics

Threads
474,164
Messages
2,570,898
Members
47,440
Latest member
YoungBorel

Latest Threads

Top