Problems associated base class C ++ ------- subclass

A, class assignment compatible principles:
 1 subclass object can be assigned to a base class object.
 Class A 
{ 
} 

class B: public A 
{ 
} 

in the main function: 
/ * 
A A1; 
B = A1 B1; // not, because the space is larger than b1 a1, a1 does not satisfy the assignment over space 
* / 

/ * 
B b1; 
a a = b1; // can, a1 b1 is used only part of the address 
* / 

2 subclass object can be used as a parent. use class object 
 (i.e., common understanding of the code subclasses have the same parent class) 


3 . base pointer can point subclass object 
  (if the object is a base class sub-class pointer, then the base class is not satisfied subclass, subclass memory layout of their base class is not being given.)
Second, the subclass constructors and destructors 
  in calling the constructor sub-class, will call the constructor for the base class is
  the base class for the first configuration, the subclass structure
  after the base class destructor, subclass first destructor
  

III subclass base class variable of the same name appears a (base class a, sub-type B)
  if the variables are of the same name as the public, and the public inheritance is
  output in a subclass the this->a, in this case is a subclass of a, to output in the base class a, need to use the domain name a :: a to display the call output


Fourth, the static member variables to the succession of
  static member variables for all family members are shared (static member variables need to be declared in the base class and a base class domain initialization)

 

Guess you like

Origin www.cnblogs.com/god-for-speed/p/10978383.html