c ++ experience 2

Class of private property is a pointer to the constructor with dynamic memory allocation when new, can not directly copy the member function directly with this property, so there will be chaos memory
Specific approach is the assignment of a value instead of a pointer.
 
Virtual:
Virtual method : If the base class is redefined in a derived class, the base class method should usually be declared virtual. Thus, the program according to the type of the object, rather than a reference or pointer to select the version type. Declare a virtual base class destructor is a common practice; virtual method using dynamic binding.
Virtual base class :
Role in the virtual base class is derived from a plurality of classes (they have a common base class) to give objects inherit a base class object
 
A positioning member of the class of meaningful virtual function is to allow C ++ function does not know the meaning, its role is just to let derived classes function overloading reserved position.
The method defines a pure virtual function is a virtual function in the class later with "= 0" flag, the event class is defined a pure virtual function, then such is an abstract class.
1 when it is desired in an abstract base class methods, and the class is the class can not be inherited when instantiated.
2, the base class must be implemented when in a derived class.
3, the plurality of abstract objects having a common property, but there are different requirements to achieve.
 
Pure virtual function:
Pure virtual function is a virtual function is declared when the "initialized" function is zero. The general form of a pure virtual function is declared virtual function type function name (parameter list column) = 0; Note: ① pure virtual function has no body; ② final "= 0" does not mean that the function returns a value of 0, only since formal role, tells the compiler system, "which is a pure virtual function"; ③ this is a declaration, should be the last semicolon. Pure virtual function and not only have the function name function, can not be called. It just tells the compiler system: "Here declare a virtual function, left derived class definitions." After providing this function is defined in a derived class, it can have a performance function can be called - This class is an abstract class, which need to achieve in a subclass
 
A method of determining an array contains several elements may be (a first array) the sizeof (array name) / sizeof
 
 
 

Reproduced in: https: //www.cnblogs.com/KyleRuan/p/4323937.html

Guess you like

Origin blog.csdn.net/weixin_33947521/article/details/93435599