fkuhl@maestro.mitre.org (F. S. Kuhl) (01/19/91)
Why does the translator (Sun packaging of AT&T 2.0) object to the following? I define in a base class SBName a virtual operator virtual SBName& operator = (const char *); which I intend to inherit in a derived class, ObjectName. In my main routine I say: ObjectName myObjName; myObjName = "hello"; and the translator says of the second line "consol.cc", line 51: error: bad argument list for ObjectName::ObjectName() (no match against any ObjectName::ObjectName()) What am I missing? -- Frederick Kuhl fkuhl@mitre.org Civil Systems Division The MITRE Corporation
steve@taumet.com (Stephen Clamage) (01/20/91)
fkuhl@maestro.mitre.org (F. S. Kuhl) writes: >Why does the translator (Sun packaging of AT&T 2.0) object to the >following? I define in a base class SBName a virtual operator >virtual SBName& operator = (const char *); >which I intend to inherit in a derived class, ObjectName... operator= is a special case. It must be a nonstatic member function of a class, and is not inherited (E&S 13.4.3, p 334-5). Briefly, assignment has a predefined meaning for a class object (memberwise copy). You are permitted to specify your own assignment operator for a class (which may do anything at all, and which need not do any assignment). It is too dangerous to blindly inherit a base class assignment operator. If the programmer specified special assignment procedures for a class, the compiler cannot make any assumptions about what should be done for a derived class. -- Steve Clamage, TauMetric Corp, steve@taumet.com
kaiser@ananke.stgt.sub.org (Andreas Kaiser) (01/22/91)
In a message of <Jan 18 20:50>, F. S. Kuhl (fkuhl@maestro.mitre.org ) writes:
FSK> Why does the translator (Sun packaging of AT&T 2.0) object to the
FSK> following? I define in a base class SBName a virtual operator
FSK> virtual SBName& operator = (const char *);
FSK> which I intend to inherit in a derived class, ObjectName.
ARM, 13.4.3, page 334:
"The assignment function operator=() must be a nonstatic member function; it is
not inherited (@12.8). Instead, unless the user defined operator= for a class X,
operator= is defined, by default, as memberwise assignment of the members of
class X."
Andreas