Static:
(1) class static data members are created and initialized at compile time, belong to a class, are not part of an object, are shared for all objects, include objects of that class's derived class, and can be accessed through the class name or object.
(2) Static member variable, can realize information sharing among similar objects. stored in the data segment (DATA-RW) {Global variables are also stored in the datastore}, so when the class size is computed, it is not counted.
(3) Static member can industry can be the optional parameter of the member function {optional parameter must be placed at the far right of the parameter table}, ordinary data members can not.
1 voidFunintAintBintC=Ten);2Fun1,2);//a=1,b=2,c=103 4 voidFunintAintb=Ten,intc);5Fun1,2);//a=1,b=? c=?
class Base {public: staticint static_var; int var ; void foo1 (int i=staitc_var); // correct void foo2 (int i=var); // Error }
(4) Type and initialization of data members:/cite https://www.nowcoder.com/questionTerminal/b73db04e98174120b50b5478839b3f8f? Orderbyhotvalue=1&mutitagids=569&page=1&onlyreference=false
| Static member |
Initialize outside the class without static decoration |
| Const member |
Can only be initialized in the initializer list after the constructor. |
| Const static Member |
Class has only one copy, and the value cannot be changed. Therefore, it can be initialized in a class, or it can be initialized outside the class like static |
(5) The meaning of static member functions is to manage static data members and complete encapsulation of static data members. Because a non-static member function is called, the this pointer is passed as a parameter, the static function member belongs to the class, does not belong to the object, and there is no this pointer, so the static function member can only access the static data member.
(6) A static member function cannot be declared as a virtual,const,volatile function at the same time.
/cite http://www.jianshu.com/p/a3303c9ba748
/cite http://www.cnblogs.com/Myhsg/archive/2009/07/31/1535650.html
Synchronous IO and Asynchronous IO:
(1) Synchronous IO, when a function call is made, the call does not return until the result is obtained.
(2) Asynchronous Io, when an asynchronous call is made, notifies the caller by state, notification, callback function.
Iocp:
(1) IOCP is an asynchronous I/O API that can efficiently notify an I/O event to an application.
Application Release for C + + memory:
(1) malloc, free cannot automatically execute constructors, destructors on objects of non-intrinsic types.
(2) Macllo, free is a library function, not an operator, so it is not within the compiler control permission. New, delete is not a library function, it is an operator, so you have permission to execute constructors and destructors.
(3) The new pointer is directly with the type information, and malloc returns a void pointer.
Pointers and references:
(1) The pointer is a variable, and the reference is an alias.
(2) The reference must be initialized at the time of definition and cannot be changed.
(3) A reference cannot be null, and the pointer can be empty.
(4) sizeof (pointer) is the size of the pointer itself, and sizeof (reference) points to the size of the object.
(5) There is no multilevel reference, and references do not need to allocate memory areas.
Polymorphic:
By using virtual functions, we implement polymorphism in subclasses by overriding them, and implement invoking the corresponding function according to the actual type of the object.
(1) A class with a virtual function has a one-dimensional virtual function table, and the object of the class has a virtual pointer to the virtual function table.
(2) An abstract class is a class that includes at least at least one pure virtual function.
The implementation principle of polymorphism:
(1) Early binding, static binding: At compile time, the compiler needs to determine the address of each object call (not a virtual function).
(2) Assuming that there is a parent class p, the parent class *PF the pointer. Subclass C, Subclass object C. Subclasses and parent classes have the same name as the function say (). When the pointer pf points to object C, calling say () through the pointer invokes the function in the parent class.
classp{ Public: voidsay () {std::cout<<"I ' m father"; }}classC: Publicp{voidsay () {std::cout<<"I ' m children"; }}voidMain () {C C; P*pf=&C; PF-say ();}
Multi-State Implementation mechanism
Understanding polymorphism first to understand the memory model of the class object.
The object memory model of the subclass is the memory of the memory + subclass of the object of the parent class, so when the subclass object is created, it first calls the constructor of the parent class, constructs the object of the parent class, and then calls the child class's constructor to complete its own construction. When you convert a subclass object to a parent class object, based on security considerations, the compiler considers the object to be the upper half of the subclass object model, which is the parent class object. Therefore, the function of the parent class object is called when the function is called using the type-converted object pointer. These are determined during compilation, in order to achieve the object and function one by one corresponding to the purpose, you need to use dynamic binding, that is, using polymorphism. In the base class, the function uses the virtual keyword, at which time the subclass is automatically added to the function with the same name, and of course you can add the virtual keyword manually. The compiler creates a virtual function table for the class with the virtual keyword (vtable) {creates the virtual table in the constructor}, which records the address of the function with the virtual key in the form of a one-dimensional array. To locate vtable, the compiler gives each object of the Class A virtual function pointer (vptr) {completes the initialization of the virtual pointer in the constructor}, which points to the vtable of the class to which the object belongs.
When the program is run, the virtual pointer is initialized according to the type of the object {when no polymorphic attribute is used, the related function is called according to the pointer/reference type} to point to the correct vtable. The virtual table can inherit, even if the subclass does not override the virtual function, the subclass still has the address of the function, if the subclass overrides the virtual function, then the new address will overwrite the inherited virtual table in the original address of the virtual function, if the child class new virtual function, the corresponding virtual function table will increase the corresponding item. Recalling the object memory model described above, the object first executes the constructor of the parent class, completes the construction of the parent class object and the virtual table and virtual pointer of the parent class, and then constructs itself.
C + + Collation