Article View: comp.std.c++
Article #3851Re: "explicit" default constructor?
From: David Vandevoorde
Date: Thu, 28 Mar 1996 16:28
Date: Thu, 28 Mar 1996 16:28
41 lines
2181 bytes
2181 bytes
>>>>> "RL" == Roman Lechtchinsky <wolfro@cs.tu-berlin.de> writes:
[...]
>> If a constructor's parameters all have default values, it can be a
>> converting constructor, and declaring it "explicit" prevents it from
>> being invoked implicitly.
RL> Yes, I've had this in mind, too. In the following case:
RL> class A
RL> {
RL> explicit A( int x=0 );
RL> };
RL> how do you call the default constructor? Can it still be invoked
RL> implicitly and what is the "explicit" syntax if not? IMO, something like
RL> A a;
RL> is not explicit ( maybe I'm wrong here and this does explicitly call the
RL> default constructor explicitly - but where does the DWP define it? ). An
RL> explicit call would rather be
Yes: the above is quite ``explicit''. Implicit would be:
a = 23; // Implicitly equivalent to `a = A(23)' if no `explicit'
// specification (and no preferred int-assignment
// alternative).
RL> A a();
This is not a constructor invacation anyway (it's the declaration of
a function `a' returning an object of type `A').
Daveed
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. 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:
<xso4tr99osk.fsf@avs.cs.rpi.edu>Path:
arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamageReferences:
<31588662.F1@cs.tu-berlin.de> <4jbqog$78i@engnews1.Eng.Sun.COM> <315A5C7A.6AF5@cs.tu-berlin.de>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage From: vandevod@cs.rpi.edu (David Vandevoorde) Newsgroups: comp.std.c++ Subject: Re: "explicit" default constructor? Date: 28 Mar 1996 16:28:41 GMT Organization: RPI Computer Science Sender: vandevod@avs.cs.rpi.edu Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <xso4tr99osk.fsf@avs.cs.rpi.edu> References: <31588662.F1@cs.tu-berlin.de> <4jbqog$78i@engnews1.Eng.Sun.COM> <315A5C7A.6AF5@cs.tu-berlin.de> NNTP-Posting-Host: taumet.eng.sun.com X-Nntp-Posting-Host: avs.cs.rpi.edu In-Reply-To: Roman Lechtchinsky's message of 28 Mar 96 09:38:43 GMT X-Newsreader: Gnus v5.1 Content-Length: 1042 X-Lines: 34 Originator: clamage@taumet