The second option is not initialization, but purpose. With types that have custom default constructors, the second option calls the default constructor, and then calls the assignment operator (regardless of whether the user specified it or not) to assign the value.
Some types cannot be initialized by default: if you have an attribute without a default constructor, hold links (constant or not) or have constant attributes, they must be initialized in the list of initializers.
Arrays can be initialized with a value in the initialization list, but not in the constructor body:
class X { public: X() : array() {}
For POD types, you can initialize their initialization in the initialization list, but not inside the brackets:
class X { public: X() : pod() {}
Finally, some classes offer functionality using constructors that will be more complex (if achievable) after building by default.
class X { public: X() : v(10) {}
Finally, when they are actually equivalent, initialization lists are more idiomatic in C ++.
David Rodríguez - dribeas
source share