Macro-defined functions
Omit the parameter type () in the return value
#define EXTERN16BYTE(x) ((x + 15) / 16 * 16)
#define isLeap(n) (n%400==0||(n%4==0&&n%100!=0)?1:0)
public\private\protected
1.private members can only be a member of this class (within the class) and friends visit, the derived class can not be accessed;
2.protected derived class members can be accessed.
public can be accessed outside the class.
inherit
Derived class inheritance
public inheritance: the parent class members maintain their level of access in a subclass
private inheritance: the parent class member in the child class become private members
protected inheritance: the parent class become protected members of the public
父类中protected成员仍然为protected
父类中private成员仍然为private
Type compatibility principle
A derived class can be used as a base class is a subclass of special parent
child class object as a parent object can use
Subclass object can be assigned directly to the parent object
Subclass object can initialize direct parent class object
Parent pointer may point directly to subclass object
Parent class reference can be directly referenced subclass object
Succession configured destructor call principle
When configured parent -> When the opposite subclass destructor
combination
Combination: class has class, emphasize has a
first configuration of the parent class, then structure member variables, and finally to construct their own
Derived class members have the same name / function
1. Call directly accessible is a subclass of members / functions
2. subclasses can be accessed by members of the same name scoping adding the parent member class / function
s1.father :: fun (110);
Access static derived class
Static members of the base class definition, are all derived classes share
the class name :: member
Virtual inheritance
If there is a common base class on multiple inheritance paths, then this will have a plurality of common base class subobject base object of a derived class inherits the merging point somewhere path
to make the common base class derived class produced only one child object, this must be the base class
as virtual inheritance declaration, the base class become the virtual base class.
class B1: public virtual A;
A pure virtual function && && abstract class virtual function
Virtual function
The role of C ++ virtual functions mainly to achieve polymorphism mechanism. The first layer is declared virtual keyword in the base class by the second layer is to be redefined in a derived class plurality.
Virtual function allows the association between a function call and the body of the function established at run
constructor may not be virtual
destructor may be a virtual function
Pure virtual function
0 = no virtual functions defined in the base class
Abstract class
Has a pure virtual function of the class is called abstract class can not be instantiated.
delete and delete [] difference
- For basic data types, the same
- For custom data type for, delete only the recovery of the memory pointer points to
delete [] array all memory recovery point