Article View: comp.std.c++
Article #3508Re: Calling X(int) from X()'s init list
From: Harald Fuchs
Date: Mon, 26 Feb 1996 17:23
Date: Mon, 26 Feb 1996 17:23
31 lines
2116 bytes
2116 bytes
alindbac@sw.seisy.abb.se (Anders Lindback) writes:
>> Why is it not allowed to delegate the initialisation to another
>> constructor
>>
>> class X
>> {
>> public:
>> X (int i) : i_(i) {}
>>
>> X () : X(34) {} // Not allowed
> Well, one could use a similar thing using a member function:
> X (int i) { init(i); }
> X () { init(34); }
> where init is a member function for class X.
The problem is that member functions can't initialize anything. Often
this is just a minor nuisance: the X ctor calls the default ctor of
the data member, which gets then immediately overwritten by assignment
in init(). But you can't use this technique when you deal with const
and reference members. Thus the syntax "X () : X(34) {}" would still
be useful. Has anyone written a proposal?
[ To submit articles: Try just posting with your newsreader.
If that fails, use mailto:std-c++@ncar.ucar.edu
FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Technical Details
Message-ID:
<pug2by80pa.fsf@themroc.colibri.de>Path:
arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamageReferences:
<4gnush$phg@news.kth.se> <4gognf$et@news.bridge.net> <4gsa2r$gjm@sdaw04.seinf.abb.se>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage From: hf@colibri.de (Harald Fuchs) Newsgroups: comp.std.c++ Subject: Re: Calling X(int) from X()'s init list Date: 26 Feb 1996 17:23:05 GMT Organization: Colibri GmbH, Germany Sender: hf@themroc.colibri.de Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <pug2by80pa.fsf@themroc.colibri.de> References: <4gnush$phg@news.kth.se> <4gognf$et@news.bridge.net> <4gsa2r$gjm@sdaw04.seinf.abb.se> NNTP-Posting-Host: taumet.eng.sun.com Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Nntp-Posting-Host: teco10a.teco.uni-karlsruhe.de In-Reply-To: alindbac@sw.seisy.abb.se's message of 26 Feb 1996 16:07:54 GMT X-Www-Home-Page: http://www.colibri.de/~hf/ X-Pgp-Public-Key: finger hf@colibri.de X-Pgp-Fingerprint: 09 4E C4 A2 B2 C5 33 1A 79 80 5D 39 BD 9B 89 39 X-Disclaimer: Kore wa Colibri no iken dewa arimasen X-Newsreader: Gnus v5.0.9 Originator: clamage@taumet