Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) access level

 

A class has three access levels:

 

A class' default access level is private. A struct's default access level is public.

 

struct MyClass
{
  //public by default, so the keyword public below is redundant
  public   : int m_public;
  protected: int m_protected;
  private: : int m_private;
};

int main()
{
  MyClass m;
  m.m_public    = 0; //OK, this member variable is public
  m.m_protected = 0; //Not allowed, this member variable is protected
  m.m_private   = 0; //Not allowed, this member variable is private
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict