13. Class member function overloading:
A function of the local name will hide instead of overloading the global Declaration, and without introducing the parent class namespace, a function with the same name as the subclass will not be overloaded with the parent class, and static member functions can be overloaded with non-static member functions.
The essence is that the definition of overloaded functions is in the same declaration domain!!! Subclasses and parent classes, both the inner and global scopes of the class are not the same scope and therefore cannot form overloads!!!
14. The compiler does not generate a default constructor when a class declares a constructor, but not a default constructor (0 parameter).
15, the constructor method is used to initialize the object of the class, unlike the other members of the parent class, it cannot be overridden by a subclass (subclasses can inherit all member variables and member methods of the parent class, but do not inherit the parent class's constructor method). Therefore, when creating a subclass object, the system needs to invoke the constructor of its parent class in order to initialize the data members inherited from the parent class.
Without an explicit constructor, the compiler gives a default constructor, and the default constructor is created only if the constructor is not explicitly declared.
The construction principles are as follows:
1. If the subclass does not have a constructor method defined, call the constructor of the parent class without arguments.
2. If a subclass defines a construction method, whether it is a parameterless or a parameter, when the object of the subclass is created, it first executes the parent class parameterless constructor, and then executes its own construction method.
3. When creating a subclass object, the default parameterless constructor of the parent class is called if the constructor of the subclass does not display the constructor that invokes the parent class.
4. When a subclass object is created, the parent class's own parameterless constructor is called if the constructor for the subclass does not display the constructor that invokes the parent class and the parent class provides itself with a parameterless constructor.
5. When creating a subclass object, if the constructor of the subclass does not show the constructor of the calling parent class and the parent class only defines its own parameter constructor, an error occurs (if the parent class has only a constructor that has parameters, the subclass must display the call to this parameter constructor).
6. If the subclass calls the parent class with the constructor of the parameter, the method of initializing the parent class member object is required
The subclass constructor must invoke the constructor of the parent class, and if you do not call the parent class without explicit invocation, the essential reason is that the nature of the inheritance determines that there must be a father and a child!
16. If a virtual function is called in a constructor or destructor, the version defined for the constructor or destructor itself is run, and the constructor and destructor do not use dynamic linking when calling virtual functions:
(1) Do not call a virtual function in a constructor: Because the parent class object is constructed before the subclass, the data member of the subclass part is not initialized, so the virtual function of the calling subclass is unsafe, and C + + does not make a dynamic union.
(2) Do not call virtual functions in destructors: destructors are used to destroy an object, and when an object is destroyed, the destructor of the subclass is called before the destructor of the base class is called. Therefore, when invoking the destructor of the base class, the data members of the derived class object have been "destroyed", and it is meaningless to call the virtual function of the subclass.
17, pure virtual function in most cases in the abstract base class is not implemented, derived from the implementation of the class. But the C + + syntax does allow the implementation to be given directly while declaring pure virtual functions.
18. Memset will be set to 0 with the virtual table pointer, which will cause an error when looking for the virtual function table at run time.
19, virtual base class is a class, only when he was the virtual inheritance of others is called the virtual base class. So: You can't say I declare a "virtual base class", but only when someone else inherits it, then it is!
20. Static member variables do not occupy the memory space of the class, and static member variables are constructed before the main function begins.
21. The static member function of a class is less than the generic member function of a class, with an implied this pointer parameter.
22. The const modifier is in the class object, which means that only constant methods and non-mutable member variables must be modified.
23, typedef int* (PF) (int, int); A function that returns a type int* is defined, and the pointer function
typedef int (*PF) (int, int); Defines a function pointer
Essence: Because the priority of "*" is lower than the priority of "()"!
24. A function pointer can be initialized or assigned with a null to indicate that the pointer does not point to any function.
25, operator precedence, highest of several
()
[]
-
.
::
++
--
26. The member function of the memory management of the class is implicitly static, and the write static is correct.
27, 1, sizeof can calculate the capacity of the array of 2, but for the pointer, can only calculate the space occupied by the pointer.
28, the programming Foundation, the preprocessing # # #, If # # uses "", start searching the header file from the current project directory, and if you use <>, start searching for the header file from the system include directory.
29, the initialization of global variables can be divided into the following two stages (c++11 N3690 3.6.2):
Static initialization refers to initializing variables with represented, mainly including zero initialization and const initialization, which are initialization during program loading. , for simple types (built-in type, pod, etc.), from the specific implementation, the zero initialization variable will be saved in the BSS section, the const initialization variable is placed in the data section, the program can be loaded to complete the initialization, and C The initialization of global variables in language is basically consistent.
Dynamic initialization: active initialization is primarily the initialization that needs to be done by a function call, such as int a = foo (), or the initialization of a complex type (class) (calls to constructors), and so on. The initialization of these variables is done by the runtime calling the appropriate code before the main function executes (except for the static variables inside the function).
Note: For global variables that appear in the same compilation unit, the order in which they are initialized is consistent with the order in which they are declared (the Order of destruction is reversed), and for global variables between different compilation units, the C + + standard does not specify what the initialization (destruction) order should be between them. So the implementation is entirely up to the compiler itself.
C + + Skills regain 2