Topic: Interpretation of default assignment operator
Author: jamshid@ses.com (Jamshid Afshar)
Date: Wed, 26 Jan 1994 22:31:46 GMT Raw View
Redirected to comp.std.c++.
In article <2i0s4i$9vf@noknic.nokia.com>,
kai sommarlund <sommarlund@trshp.ntc.nokia.com> wrote:
>In article <2hmkklINNlfd@ope001.iao.ford.com>, fox@pt0204.pto.ford.com (Ken Fox) writes:
>> /* I just ran into a problem with an "inherited" assignment. The ARM states
>> that assignment can't be inherited, but it *can* if some method uses
>> operator = in it and *that* method is inherited. [...]
>
>I don't have access to the ARM but Lippman's C++ Primer 2nd edition,
>pg. 432, states the following:
>
>"If a derived object class does not define operator= (const X&), then
>each of its base class and member class objects that defines an object
>assignment operator will have that operator invoked whenever one object
>of the derived class is assigned to another."
>
>What is this if not "inherited assignment" ?
Lippman's text is correct. I wouldn't call this "inherited"
assignment, though. I would call it a "generated" assignment operator
(that's what the ARM calls it). If something is "inherited" that
implies that it is the same function and that it does exactly what the
original function did. That is not true for the generated assignment
operator or for the generated constructors and destructor. These
generated functions are distinct and take care of data members
declared in the derived class. Also, if the assignment operator were
"inherited" the following would be legal:
class Base {};
class Derived : public Base {};
Base b;
Derived d;
d = b; // error: Base::operator=(const Base&) is not inherited
Unfortunately the ARM uses the term "default" in an extremely
confusing manner. I hope ANSI/ISO cleans things up here. The
"generated" assignment operator, no-paramater constructor, copy
constructor, and destructor are often referred to as "default". But,
the term "default constructor" is also used to refer to the (possibly
user-defined, not generated) constructor without any parameters (or
where all the parameters have, err, default values). For example:
"the default constructor will be called for every element of the
array". So, using ARM terminology, the generated default constructor
is really the "default default constructor".
Jamshid Afshar
jamshid@ses.com