Posted by Daniel Longest on April 06, 2001 at 00:13:40:
In Reply to: Re: Questions on latest homework answers posted by leon gunden on April 05, 2001 at 11:29:57:
: The question asks for the PURPOSE of the constructor member initializer list. The purpose of this language feature is to allow the programmer to pass parameters from a derived class constructor to a base class constructor (#2), and to allow parameters to be passed from an object's constructor to a data member's constructor (#?).
: Answer #3 is simply wrong. The PURPOSE of the constructor member initializer list is NOT to "construct an object's sub-objects before the rest of the object is constructed". Since this is done unconditionally, it would be ridiculous to imply that the programmer had any choice in the matter. Sub objects are constructed first whether or not a member initializer list is present (implying that if #3 was the purpose of this language feature then it is a null feature and should not have been provided).
: Hopefully someone will stop and actually consider whether #3 makes sense here before this silly argument continues further. Stroustrup addresses this feature in section 10.4.6, I can't see anywhere where the intent of #3 is mentioned.
: My intention is not to offend, only to clear up a misunderstanding.
Stroustrup in Section 10.4.6 says "The members' constructors are called before the body of the containing class' own constructor is executed." To me this says that you can use the initialization list to initialize the subobjects before the body of the constructor is executed (or the object is constructed the rest of the way). You seem to think that just becuase you aren't obligated to call the subobject's constructor, that's not a purpose of the init list, that's wrong, it is its purpose. But if the default constructor is necessary, then there's not much need to call it except for clarity (Stroustrup addresses this point in 10.6.4 as well with an example).
Post a Followup