🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Is Derived::Derived(const Base&) a copy ctor?

#2383
From: Wil Evers
Date: Wed, 01 Nov 1995 18:38
43 lines
2111 bytes

I'm trying to figure out exactly when a constructor is a copy constructor.  
The ARM, section section 12.1, says:

"A copy constructor for a class X is a constructor that can be called to  
copy an object of class X; that is, one that can be called with a single  
argument of type X."

In my interpretation, this means that if I write...

class Base { };
class Derived : public Base { public : Derived(const Base&) { } };

..then Derived will not have a generated copy constructor, since  
Derived::Derived(const Base&) is a constructor that can be called with a  
single argument of type const Derived&.

In contrast, the DWP says (12.8.2, [class.copy])

"A constructor for class X is a copy constructor if its first parameter is  
of type X& or const X&, and either there are no other parameters or all  
other parameters have default arguments."

which is different, because Derived::Derived(const Base&) does not have a  
first parameter of type Derived& or const Derived&.

Is this a deliberate change from the definition in the ARM? If so, does  
anyone know what the rationale behind this change is? (Personally, I think  
the definition in the DWP is preferable because I occasionally need to  
write such a constructor to `upgrade' a base class object to a derived  
class object and I got bitten once or twice because the compiler wouldn't  
generate a copy constructor for the derived class if I did so. Still, I  
can also imagine code that would break because of this change).

Thanks!

- Wil

---
[ 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: <1995Oct30.145329.1625@ittpub>
Path: arc1-ca.pugleaf.net!128.32.155.1!matt

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
From: wil@ittpub.nl (Wil Evers)
Newsgroups: comp.std.c++
Subject: Is Derived::Derived(const Base&) a copy ctor?
Date: 01 Nov 1995 18:38:33 GMT
Organization: <none>
Approved: matt@physics10.Berkeley.EDU (Matt Austern)
Message-ID: <1995Oct30.145329.1625@ittpub>
NNTP-Posting-Host: physics10.berkeley.edu