Explain public derivation, C/C++ Programming

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.

 

 

Posted Date: 6/28/2013 5:17:02 AM | Location : United States







Related Discussions:- Explain public derivation, Assignment Help, Ask Question on Explain public derivation, Get Answer, Expert's Help, Explain public derivation Discussions

Write discussion on Explain public derivation
Your posts are moderated
Related Questions
: Write a program that prompts the user to enter five digit positive numbers. The program then outputs the digits of the number one digit per line. Eg if the user enters 32456, th

A string S is said to be "Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''a''-''z'') and the asci


You are working for a computer gaming company and have been asked to look at a survival game.  You will be simulating a rabbit stranded on an island, collecting a large number of s


Add words in Dictionary: void Dictionary::add( Object& objectToAdd ) {     if( !objectToAdd.isAssociation() )         ClassLib_error( __ENOTASSOC );     else

Write a program that finds the minimum total number of shelves, including the initial one required for this loading process.

YOU HAVE GIVEN THE MARKED UP PRICE OF 80% AND DISCOUNT PRICE OF 10% THEN FIND THE SELLING PRICE

Define Generic Bitwise Operations? Bitwise operators only work on an incomplete number of types int and char. It turns out there's above one kind of int. In particular there's