home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!darwin.sura.net!uvaarpa!murdoch!virginia.edu!gs4t
- From: gs4t@virginia.edu (Gnanasekaran Swaminathan)
- Subject: Re: Overloaded operators and inheritance
- Message-ID: <1992Jul22.163110.3289@murdoch.acc.Virginia.EDU>
- Sender: usenet@murdoch.acc.Virginia.EDU
- Reply-To: gs4t@virginia.edu (Gnanasekaran Swaminathan)
- Organization: University of Virginia
- References: <5354@ucsbcsl.ucsb.edu>
- Distribution: usa
- Date: Wed, 22 Jul 1992 16:31:10 GMT
- Lines: 46
-
- doug@foxtrot.ccmrc.ucsb.edu (Douglas Scott) writes:
- > class QueryValue : public QueryLabel {
- > public:
- > ...
- > void operator = (const QueryValue& rhs);
- > ...
- > };
- > class StringValue : public QueryValue {
- > public:
- > virtual ~StringValue();
- > ...
- > };
- >
- > The '=' operator is implemented such that any of the derived classes should be
- > able to be assigned to one another, because I use virtual function calls to
- > both the rhs and lhs instances in the expression:
- > void
- > QueryValue::operator = (const QueryValue& rhs) {
- > set(rhs.value());
- > }
- >
- > However,
- > When I attempted to assign one of the derived class instances to another,
- > using '=', I got this compiler error:
- >
- > ./request.c:129: assignment not defined for type `StringValue'
- >
- > I looked through Stroustup, but could find no information about how operator
- > functions are inherited by subclasses. Why is '=' not defined? How does this
- > work??
-
- First, operator = (assignment operator) is not inherited by
- the derived classes. But, if you don't define an assignment
- operator in a class, a default assignment operator will be
- generated unless the class has a const member, a reference
- member, or a member or a base class with a private operator =
-
- It appears that your compiler is not able to generate a default
- assignment operator for class StringValue because of one
- of the reasons listed above.
-
- ARM has a table on p. 306 that gives a summary of the characteristics
- of operators and other functions. Perhaps, Stroustrup should include
- that table in his book.
-
- -Sekar
-