public derivationpublic derivations are much more


Public derivation

Public derivations are much more common than private derivations. In this situation:

  • The private members inherited from the base class are inaccessible to new members' functions in the derived class.
  • The public members inherited from the base class might be accessed by new members functions in the derived class and by instances of the derived class.

 e.g.

                class base

                 {

                  private :

                                                int number;

                 };

                class derived : public base

                 {

                  public :

                                                void f()

                                                 {

++number;     // Private base member not

                 accessible

                                                 }

                 };

The compiller error message is ' base :: number ' is not accessible in the function derived::f();

Here, only if the number is public then you can access it.

 

 

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: public derivationpublic derivations are much more
Reference No:- TGS0309432

Expected delivery within 24 Hours