Re: Questions on latest homework answers


[ Follow Ups ] [ Post Followup ] [ CS2704 Web Discussion Board ] [ FAQ ]

Posted by leon gunden on April 06, 2001 at 12:11:29:

In Reply to: Re: Questions on latest homework answers posted by Daniel Longest on April 06, 2001 at 00:13:40:

: : 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).

: Daniel

Obviously this thread has gone on quite long enough. But I can't seem to let this go. What you said above is correct, and I agree with you. However the question didn't say anything about initialization. It was talking about construction. There is a difference, as any self respecting C/C++ programmer should know. The purpose of the initializer list is to *initialize* the the base objects before the encapsulating object's constructor is invoked, not to *construct* the base objects. You can construct a pointer, or a built in type without initializing it. Perhaps I should have inferred the question was asking about initialization but that is not what the question said. Lets let this rest now. I can argue this point forever, but what it comes down to is that the question was worded incorrectly (it meant one thing and said another). Sorry to clutter up the message board with this garbage.

Leon




Follow Ups:



Post a Followup

Name:
E-Mail:

Subject:

Comments:

Optional Link URL:
Link Title:
Optional Image URL:


[ Follow Ups ] [ Post Followup ] [ CS2704 Web Discussion Board ] [ FAQ ]