|
|
The private access specifier declares private members of a class. It is also used to inherit a base class privately. When used to declare private members, it has this general form:
class class-name { // ... private: // private members };
Since members of a class are private by default, the access specifier private will only be used in a class declaration to begin another block of private declarations. For example, this is a valid class declaration:
class myclass { int a, b; // private by default public: // begin public declarations int x, y; // these are public private: // return to private declarations int c, d; // these are private };
When used as an inheritance specifier, private has this general form:
class class-name : private base-class { // ...
By specifying a base class as private, all public and protected members of the base class become private members of the derived class. All private members of the base class remain private to it.
|
|