// Testflag11.cpp: defines the entry point of the console application.
//
# Include "stdafx. H"
# Include "windows. H"
# Include "process. H"
Class exampletask
{
Public:
Exampletask (void)
{
Flag = true;
}
Static void taskmain (lpvoid PARAM );
Void starttask ();
Void setvalue (bool flag_1)
{
Flag = flag_1;
};
PRIVATE:
Bool flag;
};
Void exampletask: taskmain (lpvoid PARAM)
{
Exampletask * ptaskmain = (exampletask *) Param; // reference through the ptaskmain pointer
While (ptaskmain-> flag)
{
Printf ("Hello world \ n ");
Sleep (200 );
}
Printf ("thread exit \ n ");
Return;
}
Void exampletask: starttask ()
{
_ Beginthread (taskmain, 0, this );
}
Int main (INT argc, char * argv [])
{
Exampletask realtimetask;
Realtimetask. starttask ();
Sleep (3000 );
Realtimetask. setvalue (false );
Sleep (1000 );
Return 0;
}
Test results:
Private Members can be accessed in the same class!