Go Down

Topic: types o c++ (Read 766 times) previous topic - next topic

robinglow

Jul 29, 2010, 06:53 pm Last Edit: Jul 29, 2010, 06:54 pm by robinglow Reason: 1
What is public, protected, private?


msproul

In a C++ class variables and methods (routines) can be public, protected or private.

Public means they can be accessed by any other code, either inside or outside of the class.

Protected means they can only be accessed by itself and children of the class.

Private means they can only be accessed by the class, not even children of the class can access them.


PaulS

Children, in this case, means instances of classes derived from the base class, in which the public, protected, and private keywords are used.

If you don't intend to derive from a class (or support other people doing so), there is no reason to use the protected keyword.
The art of getting good answers lies in asking good questions.

Go Up