Original link: http://blog.csdn.net/yuliu0552/article/details/6631509
What are the cases in C + + that can only be initialized with a list and not assigned?
(1) For const and reference type member variables, they can only be initialized and cannot be assigned, so they can only use the initialization list;
Initialization is different from assignment:
Assignment is to delete the original value, give the new value, the constructor means to open space and then assign a value, can only be assigned, not initialized;
Initialization list is not the same, open space and initialization is done at the same time, directly give a value;
Constants cannot be assigned and can only be initialized, so they must be completed in the initialization list;
The C + + reference must also be initialized, so it has to be done in the initialization list.
【
1) references must be initialized, pointers unnecessary;
2) The reference initialization cannot be changed, and the pointer can change the object being referred to;
3) There is no reference to a null value, but there is a pointer to a null value.
】
In addition, when a subclass initializes itself, if the parent does not have a default constructor, it must also be initialized with the initial session list, and the constructor of the parent class is called in the list table
What are the cases in C + + that can only be initialized with a list and not assigned?