Member Initializer List

Jul 25, 2013 at 5:04pm
why member initializer list feature is introduced because we can also provide initialization in function's body ?
Jul 25, 2013 at 5:14pm
No we can't: every direct base and every member is initialized before the body of the constructor is entered. If you don't mention them in the list, they are default-initialized.
All you can do in the body is to replace the contents of the members, e.g. by assigning to them (where possible)
Jul 25, 2013 at 5:18pm
All data members in the body of a constructor are not initialized. They are assigned. So you can not initialize for example a constant data member, or call a constructor of an subobject with parameters, or can not call a constructor of a virtual base class.
Jul 25, 2013 at 5:29pm
class A {
const int a;
int cap;

public:
A(int ab , int capacity) {
a=ab; // Error
cap=capacity;
}
};


Am i right ???
Jul 25, 2013 at 5:35pm
It is me who is right. As for you then you are unable even to try to compile your example and to see what is the result.
Jul 26, 2013 at 3:32pm
Ok...vlad you are right ... happy ??

Thnx for the help
Jul 26, 2013 at 3:33pm
Ok vlad you r right .... Happy?

Thnx for help
Topic archived. No new replies allowed.