Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!know!zaphod.mps.ohio-state.edu!julius.cs.uiuc.edu!apple!voder!procase!roger From: roger@procase.UUCP (Roger H. Scott) Newsgroups: comp.lang.c++ Subject: Re: Need `set before used' warning Keywords: c++, warning Message-ID: <197@c.procase.UUCP> Date: 5 Oct 90 19:24:35 GMT References: <2@mtnmath.UUCP> <1990Sep27.001259.25809@relay.wpd.sgi.com> <195@c.procase.UUCP> <11745@cadillac.CAD.MCC.COM> Reply-To: roger@procase.UUCP (Roger H. Scott) Organization: proCASE Corporation, Santa Clara, CA Lines: 40 In article <11745@cadillac.CAD.MCC.COM> vaughan@mcc.com (Paul Vaughan) writes: >... >A simple argument against using the initialization form is that you have to >initialize members for each constructor, where assignments are >conveniently swept into an init function called by each constructor. >And as is pointed out above, you have to decide first whether it's >even feasible. So, how do you (anybody who is reading this) justify >this opinion? Your argument holds some water with respect to members, but doesn't apply to superclass (base class) initialization, which still must be done in each constructor. The need to repeat such initialization (both for superclasses and for members) is unfortunate. A couple of years ago I suggested to AT&T a small generalization of the language that would alleviate this problem: just as the constructor for a derived class can invoke a constructor for a base class, one constructor for a given class should be able to invoke another constructor of that same class using the identical syntax, e.g. class Base { public: Base(char *, int, int); protected: ... // member data }; class Derived : public Base { public: Derived(char *p, int i, int j, int k) : Base(p, i, j), myFoo(i + k), myBar(j + k) { } Derived(char *p) : Derived(p, 0, 0, 1) {} // build on the first one Derived() : Derived("default") {} // build on the second one protected: int myFoo, myBar; }; IMHO the preponderence of init() member functions in C++ classes throughout the world is clear evidence of a problem in the language.