This is the mail archive of the pthreads-win32@sources.redhat.com mailing list for the pthreas-win32 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: pthread_create(&ID, NULL, ***AC++MemberFunction***, NULL);


why the routine of pthread_create should be a static function:

in compilation time, the compiler need an address of the routine, non static
function has no address in the compilation time. i.e., address of automatic
class member function is resolved in run time.

--ye
----- Original Message -----
From: "Tim Hutt" <tim.hutt@btinternet.com>
To: <pthreads-win32@sources.redhat.com>
Sent: Sunday, April 07, 2002 7:07 AM
Subject: Re: pthread_create(&ID, NULL, ***AC++MemberFunction***, NULL);


> 07/04/02 14:38:30, "XDLai" <xdlai@wmlab.csie.ncu.edu.tw> wrote:
>
> >The C++ member function must be a static function.
>
> But now I cant call non-static member function of the same class from the
thread function:
>
> c:\t\cpp\killbot\bot.cpp(124) : error C2352: 'CBot::Connect' : illegal
call of non-static member function
>         c:\t\cpp\killbot\bot.h(32) : see declaration of 'Connect'
>
> I managed to get it to work another way by having it as a global friend
function of the class, and passing a pointer to the class as the paramater:
>
> CBot class
> {
>
> friend void* Main(void* pData);
>
>
> bool OtherMemberFunction();
> }
>
> void* Main(void* pData)
> {
>  CBot* pBot = (CBot*)pData;
>
>  pBot->OtherMemberFunction();
> }
>
>
>
> Suggest any better way?
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]