Initialization and assignment do not make much difference to members of built-in types, like any constructor.
But sometimes you have to use a constructor with an initialization list :
(1) The member type is
classes without a default constructor。 If no explicit initialization is provided, the compiler implicitly uses the default constructor of the member type, and if the class does not have a default constructor, the compiler attempts to use the default constructor will fail.
(2) A const member or a member of a reference type . Because const objects or reference types can only be initialized, they cannot be assigned a value.
Another number of assignments, the difference in efficiency:
Initialize the list of parameters assigns a value to a member variable at the time the object is initialized.
Directly within the constructor, assigning a value of two times to the member variable. Once the object construct is assigned with the default value, and the second is to call the constructor to assign the value
It is obvious that the constructor initializes the list with a higher efficiency
So I don't know if it's a good programming habit to use the initializer list in a constructor? The big God knows the message to know the small white bar
C + + Constructors Initialize class member variables using the difference between the initialization list and the direct assignment within the constructor