First, Inherit:
1. A derived class is a is-a (is-a-kind-of) Relationship of a base class.
2. All the functionality of a base class is meaningful to derived classes.
3. Virtual inheritance is to solve the multiple inheritance, the base class two of the meaning of the question. Detailed principle reference http://blog.csdn.net/u013630349/article/details/47057929.
Two, combination:
1. Class B is a combination of Class A, commonly referred to as a is-a-part-of relationship.
Three, polymorphic:
1. Each polymorphic class has a virtual function table (a function pointer array, placed in the static data area, not an instance, each instance is accessed with a virtual function pointer), contains the address and type information of the virtual function, and the function call resembles: (* (P->vptr[slotnum])) (p, arglist).
2. Virtual functions must have the same function prototype, but the return type can be different.
3. Polymorphic object array, access may be accessed dislocation, release memory when the subclass may not be released.
4. Derived classes cannot inherit static members of a base class.
5. The base class has been inserted into vptr, and the derived class inherits and reuses the vptr.
6. Derived classes inherit multiple classes, and each inheritance branch inherits one vptr.
The 7.vptr is typically placed at the front of the data member, to support Rtti, to create a Type_info object for each polymorphic class, with the address stored in the fixed position of the vtable (typically in the first position).
8. Since each virtual function prototype may be different, the virtual function table casts all functions into a type, holds the function address, and, when run, uses the instance object to the corresponding function, the function call resembles: (* (RealType) (P->vptr[slotnum])) (p, arglist)..
9.vptr initializes the base class vtable in the constructor, and then modifies the vtable from the derived class to overwrite the virtual function of the original base class at the same location vtable.
10. The constructor initializes the vptr, so a virtual function can be called from within the constructor using polymorphism.
Iv. Basic elements:
1.vptr, default constructor, default destructor, default copy constructor, default assignment function.
V. Objects:
1. The default constructor and default assignment function call each data member's default constructor and default assignment function, and the base data type is copied by bit.
2. Initialization list of constructors work before the function body executes, the rules are as follows:
1) class has an inheritance relationship and needs to call the constructor of the base class in the initialization list.
2) Non-crystalline const data members and reference members can only be called in the initialization list.
3) The data member is a class, put in the function body initialization efficiency is low, such as:
A::A (const a& A)
{
M_a =a;
}
First call A's default constructor to initialize M_a, and then call A's assignment function to pass a to m_a.
4) class initialization rules, first call the base class constructor in the initialization list, then call the data members of this class in the initialization list, and finally do other initialization work in the function body.
3. You cannot define both a parameterless constructor and a constructor that has default values for all parameters.
4. The copy constructor parameter must be a reference to a homogeneous object, cannot be an object value, has no other parameters, or has default values for other parameters.
C + + Class