C++

Topic: Constructors and destructors

What are using Initialization Lists to Initialize Fields ?

In case of paramterized constructor, you can use following syntax to initialize the fields:Line::Line( double len): length(len){    cout << "Object is being created, length = " << len << endl;}Above syntax is equal to the following syntax:Line::Line( double len){    cout << "Object is being created, length = " << len << endl;    length = len;}If for a class C, you have multiple fields X, Y, Z etc to be initialize then use can use same syntax and separate the fields by comma as follows:C::C( double a, double b, double c): X(a), Y(b), Z(c){  ....}

Browse random answers: