1. Overload only functions of different return types cannot be overloaded.
2. The so-called private means that the member can only be accessed by the method of the class itself-even the object of this class cannot be accessed directly.
3. the space occupied by the class object is the total memory used by its member variables (sizeof can be verified), and the Object Pointer Points to its first member variable address. object functions do not occupy the object's memory space (even if the function has local variables)
4. The main function of the const keyword is to compileProgramTroubleshooting and limiting changes to members.
It is manifested in the following aspects:
(1) const member function: const is placed after the brackets and before the semicolon. This function cannot modify member variables.
(2) const class: const is used for a class description. In fact, it indicates a const-type this pointer. This pointer can only call the const member function.
(3) const member variable: = constant
(4) const pointer.
Int * const Pi = 0; // pointer PI cannot point to other objects (Pi = & X is not allowed)
Const int * Pi = 0; // the pointer cannot change the content in the address (* Pi = x is not allowed );
Const int * const Pi = 0; // constant pointer to a constant.
5. Be sure to initialize all pointers. initialization can be a valid variable address or 0 (NULL pointer ).
All references must be initialized. The reference cannot be blank or be assigned again.
It must be kept in mind that reference is not equal to a pointer, and reference is the "alias" of the target. All referenced operations (including value assignment and &) are performed on the target.
* An uninitialized pointer is called a "out-of-control Pointer", which is very dangerous.
6. the pointer is used:
A: process data in a free storage zone;
B: member data and member functions of the category;
C: Pass objects or variables to functions by referencing them.
7. The new keyword is used to allocate memory in the heap. If the allocation is successful, an address value is returned. Otherwise, null (NULL pointer) is returned. Therefore, check whether the return value is valid every time new is used.
When a memory space is no longer needed, delete must be used for its pointer to release the target memory space.
* It indicates that when the pointer function ends, the scope of the pointer variable also ends, but the memory space pointed to by the pointer is not automatically released. Therefore, before the function ends, use delete on the pointer to release the memory space it points. otherwise, it will cause "memory loss ".
* Delete does not delete the pointer itself, so the pointer to be deleted can be assigned a value again.
* Re-use of delete on a delete pointer may cause program crash. The solution is to delete a pointer and assign it 0 immediately, while using delete on a null pointer is safe.
* Before deleting a pointer, reassigning a value to a pointer that has been assigned will lead to the loss of the previous address space.
* A good habit is that new and delete appear in pairs.
8. when you use the new operator to allocate space for a pointer to an object, the constructor of the object class is called. similarly, when Delete is used to delete an object pointer, an destructor is called.
9. If the member variable of the class is a pointer variable. Initialization can be performed in the constructor or other methods, while clearing the memory pointed to by the pointer is performed in the destructor.
In the destructor, the delete pointer member variable does not need to be assigned a value of 0, because once the object disappears, the pointer as a member cannot be accessed (of course, 0 is not harmful)
1. Overload only functions of different return types cannot be overloaded.
2. The so-called private means that the member can only be accessed by the method of the class itself-even the object of this class cannot be accessed directly.
3. the space occupied by the class object is the total memory used by its member variables (sizeof can be verified), and the Object Pointer Points to its first member variable address. object functions do not occupy the object's memory space (even if the function has local variables)
4. The main function of the const keyword is to use the compiled program for troubleshooting, and to restrict Member changes.
It is manifested in the following aspects:
(1) const member function: const is placed after the brackets and before the semicolon. This function cannot modify member variables.
(2) const class: const is used for a class description. In fact, it indicates a const-type this pointer. This pointer can only call the const member function.
(3) const member variable: = constant
(4) const pointer.
Int * const Pi = 0; // pointer PI cannot point to other objects (Pi = & X is not allowed)
Const int * Pi = 0; // the pointer cannot change the content in the address (* Pi = x is not allowed );
Const int * const Pi = 0; // constant pointer to a constant.
5. Be sure to initialize all pointers. initialization can be a valid variable address or 0 (NULL pointer ).
All references must be initialized. The reference cannot be blank or be assigned again.
It must be kept in mind that reference is not equal to a pointer, and reference is the "alias" of the target. All referenced operations (including value assignment and &) are performed on the target.
* An uninitialized pointer is called a "out-of-control Pointer", which is very dangerous.
6. the pointer is used:
A: process data in a free storage zone;
B: member data and member functions of the category;
C: Pass objects or variables to functions by referencing them.
7. The new keyword is used to allocate memory in the heap. If the allocation is successful, an address value is returned. Otherwise, null (NULL pointer) is returned. Therefore, check whether the return value is valid every time new is used.
When a memory space is no longer needed, delete must be used for its pointer to release the target memory space.
* It indicates that when the pointer function ends, the scope of the pointer variable also ends, but the memory space pointed to by the pointer is not automatically released. Therefore, before the function ends, use delete on the pointer to release the memory space it points. otherwise, it will cause "memory loss ".
* Delete does not delete the pointer itself, so the pointer to be deleted can be assigned a value again.
* Re-use of delete on a delete pointer may cause program crash. The solution is to delete a pointer and assign it 0 immediately, while using delete on a null pointer is safe.
* Before deleting a pointer, reassigning a value to a pointer that has been assigned will lead to the loss of the previous address space.
* A good habit is that new and delete appear in pairs.
8. when you use the new operator to allocate space for a pointer to an object, the constructor of the object class is called. similarly, when Delete is used to delete an object pointer, an destructor is called.
9. If the member variable of the class is a pointer variable. Initialization can be performed in the constructor or other methods, while clearing the memory pointed to by the pointer is performed in the destructor.
In the destructor, the delete pointer member variable does not need to be assigned a value of 0, because once the object disappears, the pointer as a member cannot be accessed (of course, 0 values are not harmful.)