0
Uses of member initializer list in constructors?
I'm looking for uses of initializer lists in constructors. As an example, cant always struct A { int var1; char var2; A(int a, char b) : var1(a), var2(b) {} }; be translated to struct A { int var1; char var2; A(int a, char b) { var1 = a; var2 = b; } }; ?
3 Respuestas
+ 2
As per explained in the lesson, member initializer list can be used to initialize a constant, something that cannot be accomplished with the second example above (initialization in constructor body).
+ 4
Member initializer lists are also good for execution speed because they give the compiler preciser information.
0
Member initializer lists specifies the initializers for direct and virtual base sub objects and non-static data members.