Go back to Richel Bilderbeek's homepage.

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

 

 

 

(C++) protected

 

Keyword for setting class access level to protected (the other access levels are private and public) or for protected inheritance.

 

 

 

 

class Base

{

protected: int m_x;

};

 

class Derived : public Base

{

void ResetX() { m_x = 0; } //For a derived class (only) m_x is public

};

 

int main()

{

Base b;

b.m_x = 0; //Not allowed! Only derived classes have access to Base::m_x

}

 

 

 

 

 

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

Go back to Richel Bilderbeek's homepage.