Some of the knowledge points of C + + are fragmented, the following list of forms to do some recording and induction, for reference.
1. Assignment operator overloading (deep copy):
(1) Since the target object may refer to some previous data, the data should be delete first;
(2) Notice that the object may be assigned to itself, so add the following statement (another for another object), and then do (1):
(3) The function returns a reference to the calling object;
(4) Assignment operators can only be overloaded with member functions.
2. Static class member functions:
(1) The static class member function is to add the static keyword in the declaration of the class, but not in the definition;
(2) Static class member function does not use this pointer;
(3) If a static class member function is declared in the public part, it can be invoked using the class name and the domain resolution operator.
3, the use of new in the constructor:
(1) If new is used in the constructor to initialize the pointer member, delete should be used in the destructor;
(2) New and delete must correspond, new corresponds to delete,new[] corresponding to delete[];
(3) If you have more than one constructor, you must call new in the same way, either new or new[], because there is only one destructor, and all constructors should be compatible with it.
4. The function returns the object:
(1) Returns a reference to a const object:
<1> the return object invokes the copy constructor, and the call to return the object does not, so the efficiency is improved;
The object that the <2> reference points to should exist when the function executes.
(2) Returns a reference to a non-const object, typically in two cases:
<1> overloading the assignment operator so that it can be assigned continuously;
<2> overloads the << operator that is used with cout to enable it to thread the output, returning in the form of: Ostream &.
(3) Return non-const object:
If the returned object is a local variable in the function, the reference cannot be returned, but the object should be returned, because the function executes the local variable to be destroyed, the reference will be invalidated, and the returned object will call the copy constructor to generate the temporary object.
To IS continued.
C + + fragmented knowledge points