Re: Reference assignment through base class reference
On Jun 5, 7:27 pm, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
James Kanze wrote:
On Jun 5, 3:06 pm, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
James Kanze wrote:
[..]
In general, assignment doesn't work well with polymorphic
objects. Typically, if a class is designed to be used as a
base, it will have a private assignment operator, so that such
code will be illegal.
*Private* assignment operator? Not *protected*? Just trying to
clarify...
Private. Why would you make it protected, if the goal is to ban
it? Alternatively, you could inherit from something like
boost::uncopiable.
If a class is designed to be used as a base, and its assignment op
is private, how the hell are you going to copy the derived class
objects?
You're not going to assign them. (A protected copy constructor
is sometimes appropriate. Although in most cases, if a class is
designed to be used as a base class, it has no data to be
copied.)
The default copy assignment op cannot be generated, so
a user-defined has to be provided, which will have to forgo copying
of the base part, which means only the derived portion can be made
"the same as the other one", and the base class subobject will have
to stay the way it was created...
No. The derived class doesn't have to do anything. Assignment
is just not part of the contract, and thus not supported.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34