Is-a, Has-a, and like-a, grouping, aggregation, and inheritance the difference between the two sets of concepts-cbk861110 column-Blog channel-Csdn.net http://blog.csdn.net/cbk861110/article/details/9028189
Public succession emphasizes the relationship of is-a, emphasizing one kind of inheritance relation, and has-a emphasizes a kind of subordinate relation.
The form of inheritance is: Class derived:public based
Public inheritance is characterized by the public and protected members of the base class as members of derived classes, which remain in their original state, while private members of the base class are still private and accessible only through the public or protected members of the base class.
Derived classes inherit the constructor of the base class, so derived classes must define their own constructors.
When using a derived class constructor:
1. You must first call the base class constructor to create the base class Derived::D erived (...): Based () {...}
2. The derived class constructor can pass the information of the base class to the base class constructor through the member initialization list.
3. Derived class constructors should initialize new data members of derived classes
when a derived class expires, the destructor for the derived class must be called before the accumulated destructor is called Derived::~derived () {... ~baesd ();}
The relationship between a derived class and a base class
1. Derived classes can only invoke the public members of the base class, and for private members only through the public or protected members of the base class
2. Base-class pointers and references can point to derived class objects without a display conversion, namely:
The ① parameter is a function of the base class reference (or pointer) that can use the base class object (the address) or the derived class object (the address) as the argument
② can initialize base class objects with derived class objects
3. A base class reference or pointer can only be used to call a base class method and cannot be used to invoke a method of a derived class
C + + public inheritance