I read the discussion about pointers and references on the Internet today, and I have a bit of understanding. The record is as follows.
It is introduced in C ++ when it is referenced. It is essentially a pointer and is a special pointer.
1) It must be initialized and there is no null reference.
2) When being passed as a parameter, no parameters are required. The pointer effect is the same as the pointer reference. You can modify the pointer itself (that is, the pointer represents the memory address ).
Pass value: the role of the real parameter is not only for the initialization of the form parameter, but also has no effect.
But when the application is passed, there is no form parameter, and the object itself is involved.
In my opinion, the so-called address transfer is actually a fax, but it only refers to the address, and there are also parameters involved. Therefore, if the parameters themselves (instead of what the parameters point to) are modified, the real parameters cannot be synchronized. For example, if a pointer is a shortcut, you can modify the object pointed to by the shortcut, so the shortcut pointing to the object can be synchronized. However, if you modify a shortcut and direct it to another object, there is no connection between other shortcuts and the shortcut.
3) The referenced object cannot be changed. This is the same as const modification.
4) when it is returned, the reference will not trigger the copy constructor of the class.
Generally, a temporary variable is generated and the copy constructor of the class is called.
By the way, how can I initialize the const member variable in the class.
We all know that the const variable needs to be initialized, but how does one initialize the const member variable in the class?
In the constructor? This is definitely not acceptable. It is a value assignment instead of initialization. The answer is to initialize the constructor in the initialization list, which is executed before the constructor of the execution class. In this way, the object of each class can be initialized to different values.
Static variables are declared in. h and must be initialized in. cpp. The global location is preceded by the scope of the class, because it does not belong to an object, but all objects are shared and belong to the entire class. Static const is also initialized.