class CC
{
public :
CC (); //line 1
CC (int); //line 2
CC (int, int); //line 3
CC (double, int); //line 4
.
.
.
private:
int u;
double v;
};
a. give the line number containing the constructor that is executed in each of the following declarations:
i. CC one;
ii. CC two(5, 6);
iii. CC three(3.5, 8);
b. write the definiiton of the constructor in line 1 so that the private member variables are initialized to 0.
c. write the definition of the constructor in line 2 so that the private member variable u is initialized according to the value of the parameter, and the private member variable v in initialized to 0.
b. It isn't wrong but using an initializer list is better: CC() : u(0), v(0) {}
For performance or ease-of-reading?
I haven't really come across a source where they actually teach this method so I was fairly confused the first time some of you more advanced programmers told me about this.
i usually dont use the initializer list because I usually have error checking I want to perform. Its pretty standard to use the lists if you are using inheritance though