Posted by leon gunden on April 05, 2001 at 11:29:57:
In Reply to: Re: Questions on latest homework answers posted by William D McQuain on April 05, 2001 at 08:21:55:
: : I have a couple questions on the latest home work assignment on
: : inheritance.
: : First, on question number 19, I think the answer should be 2, rather
: : than 5 (2 + 3). Answer 3 states "to construct an object's sub-objects
: : before the rest of the object is constructed," however this is not
: : entirely correct. The sub-objects of a class are always implicilty
: : constructed prior to the rest of the object, the member initializer
: : list allows the programmer to explicitly call a specific constructor
: : of the sub-object. The member initializer list does NOT allow the
: : programmer to change the default construction order.
: So? Answer #3 does not say the initializer list allows a change in construction order. The initializer list may be used to specify non-default behavior during the construction of sub-objects, or even redundantly to specify default behavior. Either way, the initializer list is being used to effect the construction of sub-objects. That's all answer #3 says; it doesn't even say that using the initializer list is the ONLY way to construct sub-objects, which seems to be how you're interpreting it.
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.
Post a Followup