Article View: comp.std.c++
Article #3502Re: Calling X(int) from X()'s init list
From: Anders Lindback
Date: Mon, 26 Feb 1996 16:07
Date: Mon, 26 Feb 1996 16:07
37 lines
1693 bytes
1693 bytes
In article <4gognf$et@news.bridge.net>,
David Byrden <100101.2547@compuserve.com> wrote:
><<<<<<<
>
>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
>>>>>>>>>>
>
>
> Why not use X (int i = 34 ) : i_(i) {}
>[ I think he was concerned with the more general case of a complicated
> initialization (not assignment) that must be repeated for each
> constructor. -sdc, moderator
>]
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.
Anders
[ 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:
<4gsa2r$gjm@sdaw04.seinf.abb.se>Path:
arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamageReferences:
<4gnush$phg@news.kth.se> <4gognf$et@news.bridge.net>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage From: alindbac@sw.seisy.abb.se (Anders Lindback) Newsgroups: comp.std.c++ Subject: Re: Calling X(int) from X()'s init list Date: 26 Feb 1996 16:07:54 GMT Organization: ABB Industrial Systems AB, Vdsteres, Sweden Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <4gsa2r$gjm@sdaw04.seinf.abb.se> References: <4gnush$phg@news.kth.se> <4gognf$et@news.bridge.net> Reply-To: alindbac@sw.seisy.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: ws222.sw.seisy.abb.se Originator: clamage@taumet