🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3843

Re: "explicit" default constructor?

#3843
From: Roman Lechtchinsky
Date: Thu, 28 Mar 1996 09:38
63 lines
3280 bytes
Steve Clamage wrote:

> In article F1@cs.tu-berlin.de, Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
> writes:
> 
> > as I read the section [class.conv.ctor] of the DWP, I get the
> > impression that the description of converting and non-converting
> > constructors applies to all constructors, i.e. a constructor is either
> > converting or non-converting. A non-converting constructor creates an
> > object "only where a constructor call is  explicitly  indicated by the
> > syntax". This has no implications on constructors with more than one
> > parameter, but what about the default constructor? Should a default
> > constructor call be really indicated by the syntax and if so, how is it
> > to be done? What if the default constructor is declared "explicit"?
>
> A converting constructor is one which can be called with a single parameter.
> The default constructor isn't a converting constructor except in the
> case of a constructor with all parameters having default values.
> 
> If a constructor has no parameters, declaring it "explicit" has no effect,
> since it can never be invoked for a conversion.
> 

Exactly this is my question. Does this section deal only with constructors 
with one parameter ( i.e. those that could be converting )? I read it this 
way: if a constructor is not a converting constructor, i.e. it either doesn't 
have exactly one parameter or is declared explicit, it is a non-converting 
constructor and a call should be explicitly indicated by the syntax. In this 
case the default constructor is non-converting.

> 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.

Yes, I've had this in mind, too. In the following case:

class A
{
 explicit A( int x=0 );
};

how do you call the default constructor? Can it still be invoked implicitly 
and what is the "explicit" syntax if not? IMO, something like

A a;

is not explicit ( maybe I'm wrong here and this does explicitly call the 
default constructor explicitly - but where does the DWP define it? ). An 
explicit call would rather be

A a();

but what is the point in using this syntax?

Bye

Roman
---
[ 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: <315A5C7A.6AF5@cs.tu-berlin.de>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
References: <31588662.F1@cs.tu-berlin.de> <4jbqog$78i@engnews1.Eng.Sun.COM>

Show Full Headers
Complete Article Headers
From: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
Message-ID: <315A5C7A.6AF5@cs.tu-berlin.de>
X-Original-Date: Thu, 28 Mar 1996 10:31:38 +0100
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 28 Mar 96 09:38:43 GMT
Approved: fjh@cs.mu.oz.au
Newsgroups: comp.std.c++
Subject: Re: "explicit" default constructor?
Organization: Technical University of Berlin
References: <31588662.F1@cs.tu-berlin.de> <4jbqog$78i@engnews1.Eng.Sun.COM>
X-Mailer: Mozilla 2.0 (Win95; I)
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMVpebeEDnX0m9pzZAQEI0AF8C6YpDNsbyEL1eTmYXDWN6JvM0s9/AJgq
 hsZVpdG8FnSlyG+FJkGTOKmrsHT/ZxWz
 =R5Uq