I was going through some of the questions on constructor initialization list when I bumped into this.
Consider this:
class Student {
public:
Student() {
id = 0;
}
Student(int i) {
id = i;
}
private:
int id;
};
Now, check this out:
By the time you get in the body of the constructor, all fields have already been constructed; if they have default constructors, those were already called. Now, if you assign a value to them in the body of the constructor, you are calling the copy constructor. That is inefficient, because two constructors end up being called instead of one.
Source: What does a colon following a C++ constructor name do?
So, does it mean that when I call the parameter-less constructor, the copy constructor is also being called?
Please explain. This is really confusing.
Particularly the meaning of the first line:
By the time you get in the body of the constructor, all fields have already been constructed