Re: Reference assignment through base class reference
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? 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... That's just wrong, it meanst that
if I have
Derived d1(some_params), d2(some_other_params); // different
assert(d1 != d2);
d1 = d2;
assert(d1 == d2); // how is that going to be true if '=='
// compares the base part as well?
So, either _in_general_ comparing objects of derived class should
NOT involve comparing base class subobjects (which is just wrong
*in general*), or there should be a way to assign bass class
subobjects in a derived class copy assignment operator, which
means the copy assignment operator should be probably *protected*
_in_general_ if the class is intended to serve as a base.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask