Topic: Is this a copy constructor? (subtle ARM/DRAFT difference)


Author: sdouglass@armltd.co.uk (scott douglass)
Date: 16 Feb 1995 13:21:05 GMT
Raw View
In the ARM, section 12.1 say "A copy constructor for class X is a
constructor ... that can be called with a single argument of type X."

[It gives 'X::X(const X&)' and 'X::X(X&,int=0)' as examples. and
specifically disallows 'X::X(X)', but that it not important to my
question.]

Thus, given:
  class B { int b; };
  class D : B { D(const B&); };

The ARM considers 'D::D(const B&)' a copy constructor, and therefore no
default copy constructor will be generated.

Also, given:
  class T { T(X); operator X(); };

'T::T(X)' is also a copy constructor, albeit an obscure one.

In the Sept. DRAFT the language has been changed to "A copy constructor
for a class X is a constructor whose first parameter is of type X or const
X& and whose other parameters, if any, all have defaults, so that it can
be called with a single argument of type X."

This prevents both of the above examples from being copy constructors.
This broke my code (silently, no less), so my questions are:
  Why was this changed?
  Was it intentional that 'D::D(const B&)' no longer be a copy constructor?

The same change was applied to operator=(), so my questions apply to it as well.

[It might be a good idea the change "A copy constructor for a class X is a
constructor whose ..." to "A copy constructor for a class X is a
constructor of class X whose ..." just to prevent the bizzare
interpretation of 'Y::Y(const X&)' as a copy constructor for class X.]

Thanks for your thoughts,
      --scott
       --scott