static function vc++
-
:(Hello!, I have a problem with static function, to access to member variable at same dialog class, both the static function and member variable are class members. The problem begin when i try compile a program with a function in a AfxBeginThead instruction with errors. I solve that problem, using a static function, but now i can't access a data member variable, of the dialog class of my project. Please help me!!! Thank for your collaboration. greating. mperlera
-
:(Hello!, I have a problem with static function, to access to member variable at same dialog class, both the static function and member variable are class members. The problem begin when i try compile a program with a function in a AfxBeginThead instruction with errors. I solve that problem, using a static function, but now i can't access a data member variable, of the dialog class of my project. Please help me!!! Thank for your collaboration. greating. mperlera
Since static functions do not have an implicit 'this' pointer, you cannot access any member (non-static) functions or data from within the static function. However, AfxBeginThread() allows to provide a user-defined parameter to your static thread function. In this case, you can pass in the pointer to the dialog as the user-defined parameter, and then use that within your thread function to get at the members. Dave http://www.cloudsofheaven.org
-
:(Hello!, I have a problem with static function, to access to member variable at same dialog class, both the static function and member variable are class members. The problem begin when i try compile a program with a function in a AfxBeginThead instruction with errors. I solve that problem, using a static function, but now i can't access a data member variable, of the dialog class of my project. Please help me!!! Thank for your collaboration. greating. mperlera
What you usually do is something like the following:
UINT CMyClass::ThreadFunc(LPVOID p) //this is your static func
{
CMyClass* pMyClass = (CMyClass*)p;p->SomeNonStaticFunc(); //access non-static member functions
p->DataMember = 0; //access non-static member data
...
return 0; //return your thread exit code
}void CMyClass::SomeFunc()
{
AfxBeginThread(ThreadFunc, this); //start your thread function
}--Dean