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; } }; ?

29th May 2018, 1:53 PM
Bebida Roja
Bebida Roja - avatar
3 Answers
+ 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).
29th May 2018, 2:02 PM
Ipang
+ 4
Member initializer lists are also good for execution speed because they give the compiler preciser information.
29th May 2018, 5:08 PM
Timon Paßlick
0
Member initializer lists specifies the initializers for direct and virtual base sub objects and non-static data members.
11th Dec 2018, 10:57 AM
Birhan Tassew Reda
Birhan Tassew  Reda - avatar