Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language:
Expertise: Intermediate
Apr 5, 2002

Use a Non-Static Member Variable or Function in a Static Member Function

 
//  This example shows how we can use a non static
//  member variable or function in a static
//  member function

class CClass
{
public:
  int m_Var;
private:
  static CClass m_ptClass
public:
  static void StaticMemberFonction();
}
CClass::CClass()
{
  ptClass = this; // OK
}
void StaticMemberFonction()
{
  // m_Var = 10; // WRONG: cannot acces to m_Var
  // this->m_Var = 10; //WRONG: cannot acces to
                       // this pointer
  m_ptClass->m_Var = 10; // OK
}
Manuel Goacolou
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date