Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!rutgers!usc!elroy.jpl.nasa.gov!cit-vax!ronen From: ronen@cit-vax.Caltech.Edu (Ronen Barzel) Newsgroups: comp.lang.c++ Subject: Re: Class member initialization proposal Message-ID: <14589@cit-vax.Caltech.Edu> Date: 13 Apr 90 22:18:07 GMT References: <14560@cit-vax.Caltech.Edu> <1990Apr13.064548.1133@sjsumcs.sjsu.edu> Reply-To: ronen@cit-vax.UUCP (Ronen Barzel) Organization: California Institute of Technology Lines: 30 In article <1990Apr13.064548.1133@sjsumcs.sjsu.edu> horstman@sjsumcs.SJSU.EDU (Cay Horstmann) writes: > ...The only benefit would be to give the >compiler a hint to factor out code common to all constructors. But you >could do that manually with a member function. You can't do it in all cases. From Lippman, sec 6.1 p.243: "The member initialization list is the only mechanism by which const and reference class data members can be initialized." Thus const and reference initializations can't be factored out into a member function. >HOWEVER, for static const this would indeed be very desirable: I agree. Even for static but non-const. In summary, I think it's desirable to specify an initialization for anything as part of (or at least along with) its definition. [Anybody care to argue with this claim?] Along the same lines, it would be nice to specify default parameters to base class constructors. Again, this is something that can't be factored out into a member function. e.g.: OLD NEW ---------------------- ------------------------------ class A : public B { class A : public B(3,"foo") { A(); A(); }; }; A::A() : B(3,"foo") A::A() { /* body */ } { /* body */ } Does g++ support this too? -Ronen