Topic: Relaxing the definition of copy-constructor


Author: Ralf Boecker <boecker@hrz.uni-kassel.de>
Date: 1995/07/28
Raw View
vandevod@hotplate.cs.rpi.edu (David Vandevoorde) wrote:

>Consider:
>
>struct B {
>    // ...
>};
>
>struct D: B {
>    D(const B&); // Not a copy-constructor
>    // D(const D&);     // If not provided, will produce a
>    // ...              // default copy-constructor.
>};
>
>I find that in most cases where D does not add data members to B,
>the constructor D(const B&) and the copy-constructor D(const D&)
>are the same.
>
This is exactly what the compiler generates:
The default copy c-tor & assignment operator generated for D
call the copy c-tor & assignment operator defined for B respectively.
If D does not declare any additional members, the compiler does nothing else.

--
*** Dipl.-Ing.  Ralf  Boecker    Universitaet GH Kassel     ***
*** eMail: boecker@hrz.uni-kassel.de  FB 16 - Elektrotechnik     ***
*** Tel: (+49)561/804-6404    Wilhelmshoeher Allee 73    ***
*** Fax: (+49)561/804-6360    D-34121 Kassel (Germany)   ***







Author: vandevod@avs.cs.rpi.edu (David Vandevoorde)
Date: 1995/07/28
Raw View
In article <3v2uad$nep@mloeff01.elec.mid.gmeds.com>,
Ramesh.S <rameshs@ix.netcom.com> wrote:
[...]
>
>What is expectation for the following situations ?
>
>struct B {
>   // ...
>};
>
>struct C {
>   //...
>};
>
>struct D: B, C
>{
> D (const C&); // here which one should be the copy ctor ?
> D (const B&); // or no copy ctor ?
>};

Excellent point. Thanks.
[...]
>
>I feel this feature is not possible. And even if it is implemented
>it may lead to somemore ambiguities to the language.

I agree.
>
>- Ramesh.S
>
 Daveed






Author: rameshs@ix.netcom.com (Ramesh.S)
Date: 1995/07/25
Raw View
In article <3urndh$agp@usenet.rpi.edu>, vandevod@hotplate.cs.rpi.edu (David Vandevoorde) says:
>
>I've asked this one or two months ago already, but did not see any
>answers (or missed them somehow).
>
>Consider:
>
>struct B {
>    // ...
>};
>
>struct D: B {
>    D(const B&);        // Not a copy-constructor
>    // D(const D&);     // If not provided, will produce a
>    // ...              // default copy-constructor.
>};
>
>I find that in most cases where D does not add data members to B,
>the constructor D(const B&) and the copy-constructor D(const D&)
>are the same.
>
>Somehow, I feel that D(const B&) should be used as a copy-constructor
>if D(const D&) is not provided. I think it's rather consistent with
>the idea that a reference to a derived object can transparently be
>reduced to a reference to its base subobject.
>
>Opinions welcome,
>
>        Daveed
>

What is expectation for the following situations ?

struct B {
   // ...
};

struct C {
   //...
};

struct D: B, C
{
 D (const C&); // here which one should be the copy ctor ?
 D (const B&); // or no copy ctor ?
};

struct E : B
{
   //...
};

struct F : E
{
       // here do you want to treat it as copy ctor ?
       F ( const B& );
};

I feel this feature is not possible. And even if it is implemented
it may lead to somemore ambiguities to the language.

- Ramesh.S








Author: vandevod@hotplate.cs.rpi.edu (David Vandevoorde)
Date: 1995/07/22
Raw View
I've asked this one or two months ago already, but did not see any
answers (or missed them somehow).

Consider:

struct B {
    // ...
};

struct D: B {
    D(const B&); // Not a copy-constructor
    // D(const D&);     // If not provided, will produce a
    // ...              // default copy-constructor.
};

I find that in most cases where D does not add data members to B,
the constructor D(const B&) and the copy-constructor D(const D&)
are the same.

Somehow, I feel that D(const B&) should be used as a copy-constructor
if D(const D&) is not provided. I think it's rather consistent with
the idea that a reference to a derived object can transparently be
reduced to a reference to its base subobject.

Opinions welcome,

 Daveed