home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!news.acns.nwu.edu!network.ucsd.edu!ucsbcsl!foxtrot!doug
- From: doug@foxtrot.ccmrc.ucsb.edu (Douglas Scott)
- Newsgroups: comp.lang.c++
- Subject: Overloaded operators and inheritance
- Message-ID: <5354@ucsbcsl.ucsb.edu>
- Date: 21 Jul 92 23:37:26 GMT
- Sender: root@ucsbcsl.ucsb.edu
- Distribution: usa
- Organization: Center for Computer Music Research and Composition, UCSB
- Lines: 50
-
- I have a class in which I overload the = operator:
-
- class QueryValue : public QueryLabel {
- public:
- QueryValue(const char *, CharCheckFun ccf, LegalValueFun lvf);
- virtual ~QueryValue();
- ...
- void operator = (const QueryValue& rhs);
- ...
- };
-
- I then define several subclasses derived from this one:
-
- class StringValue : public QueryValue {
- public:
- StringValue(const char *, const char *, CharCheckFun ccf, LegalValueFun lvf);
- StringValue(const char *value=nil);
- virtual ~StringValue();
- ...
- };
-
- etc.
- 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??
-
- Thanks in advance.
-
-
- --
- Douglas Scott (805)893-8352
- Center for Computer Music Research and Composition
- University of California, Santa Barbara
- Internet: (NeXTMail ok) <doug@foxtrot.ccmrc.ucsb.edu>
-