🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Explicit-keyword and default constructors

#1911
From: Pulkkinen Esa
Date: Tue, 05 Sep 1995 15:05
46 lines
2260 bytes
I'm sorry, if this question has been asked before, I remember a related
discussion, but I can't recall, if this question was answered.

Consider this example:

class A
{
public:
  explicit A() {}
};
A a; // Legal? (IMHO: no)
A b=A(); // OK, as always
A c(); // OK, c is a function returning A :)

class B : public A {} 
// Default constructor generated, and calls A()? Legal? 
// (IMHO: no)

What is the current interpretation of the above program?

My analysis:
[dcl.fct.spec]/5 states:
"The explicit-specifier shall be used only in declarations of constructors
within a class declaration."

[class.conv.ctor]/1:
"A constructor declared without the function-specifier explicit
that can be called with a single parameter specifies a conversion
from the type of its first parameter to the type of its class.
Such a constructor is called a converting constructor."

These were the only places I could find, where the semantics of 
the explicit specifier was explained. The first one clearly (?) states
that the explicit-specifier can be used for any kind of constructor.
The [class.conv.ctor] only defines the behaviour when the constructor
can be called with one parameter.
So, where does the WP define the semantics of an explicit-keyword
applied to a default constructor (or any other constructor that can't
be called with a single parameter...)?
---
  Esa Pulkkinen               | C++ programmers do it virtually always
  esap@cs.tut.fi              | with classes, resulting in multiple
  http://www.cs.tut.fi/~esap/ | inheritance.
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <42gjou$1m9@proffa.cc.tut.fi>
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage
From: p150651@proffa.cc.tut.fi (Pulkkinen Esa)
Newsgroups: comp.std.c++
Subject: Explicit-keyword and default constructors
Date: 5 Sep 1995 15:05:04 GMT
Organization: Tampere University of Technology
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <42gjou$1m9@proffa.cc.tut.fi>
NNTP-Posting-Host: taumet.eng.sun.com
Content-Type: text
Content-Length: 1758
X-Lines: 54
Originator: clamage@taumet