Topic: If no cp ctor, why not def ctor and assignment?
Author: peter@chinook.physics.utoronto.ca (Peter Berdeklis)
Date: 1995/05/17 Raw View
Hi everyone.
I understand that it is more efficient to define a copy ctor
than to call the default ctor followed by the assignment
operator.
The WP says that if a copy ctor is not provided by the user then
the compiler will provide one. Again, I understand that a
simple memberwise copy will be sufficient for many situations.
However, if the user has provided an assignment operator and a
default ctor (if necessary), but has neglected to provide a copy
ctor for some reason, wouldn't it be better if the compiler used
the default ctor/assignment pair and flag a warning, than to have
the compiler just do a dumb copy?
Was there some reason for omitting this possibility from the WP?
Of course, I'm not suggesting that users should not provide a copy
ctor, and that this should be a lazy alternative. I just think
that since it would be easy to implement, and more often correct,
that it should be part of the language definition.
Pete
Author: kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763)
Date: 1995/05/18 Raw View
In article <D8qI1t.4CC@info.physics.utoronto.ca>
peter@chinook.physics.utoronto.ca (Peter Berdeklis) writes:
|> I understand that it is more efficient to define a copy ctor
|> than to call the default ctor followed by the assignment
|> operator.
|> The WP says that if a copy ctor is not provided by the user then
|> the compiler will provide one. Again, I understand that a
|> simple memberwise copy will be sufficient for many situations.
|> However, if the user has provided an assignment operator and a
|> default ctor (if necessary), but has neglected to provide a copy
|> ctor for some reason, wouldn't it be better if the compiler used
|> the default ctor/assignment pair and flag a warning, than to have
|> the compiler just do a dumb copy?
|> Was there some reason for omitting this possibility from the WP?
Basically, it's more that there was no overriding reason for having
it. Why make things more complicated than they have to be.
|> Of course, I'm not suggesting that users should not provide a copy
|> ctor, and that this should be a lazy alternative. I just think
|> that since it would be easy to implement, and more often correct,
|> that it should be part of the language definition.
Why not ask your compiler vendor to provide a warning when there is a
user provided assignment operator and no copy constructor? (The case
is almost always an error.)
--
James Kanze Tel.: (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils en informatique industrielle --
-- Beratung in industrieller Datenverarbeitung