private inheritance

Single Inheritance – Private Inheritance in C++

Let us understand what does private inheritance mean… Consider a simple example to illustrate the single inheritance. The Program given below shows a base class B and a derived class D. The class B contains one private data member, one public data member and three public member functions. The class D contains one private data member and two public member functions. #include<iostream.h> class B { private: int a; //private; not inheritable public: int b; //public; ready for inheritance void get_ab(); int get_a(); void show_a(); }; class D : private B //private derivation { private: int c; public: void mul(); void display(); }; In private derivation, the public members of the base class becomes private members of the derived class. Therefore, the objects of the derived class D cannot have direct access to the public member functions of the base class B. Hence, if we create an object of the derived...

Defining of Derived Classes in C++

How do we define a derived class in C++ A derived class is defined by specifying it relationship with the base class in addition to its own details. The general form of defining a derived class is: class derived-class-name : visibility-mode base-class-name { … … //members of derived class … }; where, class is the required keyword, derived-class-name is the name given to the derived class, base-class-name is the name given to the base class, : (colon) indicates that the derived-class-name is derived from the base-class-name, visibility-mode is optional and, if present, may be either private or public. The default visibility-mode is private. Visibility mode specifies whether the features of the base class are privately derived or publicly derived. Examples: class ABC : private XYZ //private derivation { members of ABC }; class ABC : public XYZ //public derivation { members of ABC }; class ABC : XYZ //private derivation...