Inheritance and derived C ++ class

 

 Inherited advantages: reducing redundant code to improve code reusability

Definition Format derived class: 
   Class derived class name: the name of the base class inheritance { 
         // derived class new data members and member functions 
   };
    class subclasses: the name of the parent class inheritance {
        // the subclass data members and additional member function 
   };

Inheritance Category:

public: public inheritance (important)
private: private inheritance
protected: protected inheritance

note:

Subclasses inherit the parent class, subclass has all of the parent class member variables and member methods (in addition to constructor and destructor member methods) , but in the subclass, and inherited members may not be able to directly access , different inheritance approach will lead to different access rights.
(Public inherits the parent class's private data is not visible to other intact in a subclass)
(Protection class inherited his father's private data is not visible to the subclass other data protection has changed)
(Private inherit the parent class's private data is not visible in other subclasses become private)

 

 No matter what inheritance: the parent class's private data is not visible in a subclass

Order of succession of the constructor and destructor

. 1  class Base
 2  {
 . 3  public :
 . 4      Base ()
 . 5      {
 . 6          COUT << " no parent class constructor parameter " << endl;
 . 7      }
 . 8      ~ Base ()
 . 9      {
 10          COUT << " Analysis of the parent class structure function " << endl;
 . 11      }
 12 is  };
 13 is  class Son: public Base
 14  {
 15  public :
 16      Son ()
. 17      {
 18 is          COUT << " constructor without parameters subclasses " << endl;
 . 19      }
 20 is      ~ Son ()
 21 is      {
 22 is          COUT << " subclass destructor " << endl;
 23 is      }
 24  };
 25  void Test01 ()
 26 is  {
 27      Son OB1;
 28 }

to sum up:
Construction order: the parent class (class-yl) configured ------> subclass (derived class) configured
Destructor sequence: subclass (derived class) destructor ------> parent (base class) destructor

 

 The main master inheritance goes coordinates for the content of this knowledge is not much wrong with me ..

Guess you like

Origin www.cnblogs.com/loliconinvincible/p/12562780.html