home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11288 < prev    next >
Encoding:
Text File  |  1992-07-21  |  1.7 KB  |  62 lines

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!news.acns.nwu.edu!network.ucsd.edu!ucsbcsl!foxtrot!doug
  2. From: doug@foxtrot.ccmrc.ucsb.edu (Douglas Scott)
  3. Newsgroups: comp.lang.c++
  4. Subject: Overloaded operators and inheritance
  5. Message-ID: <5354@ucsbcsl.ucsb.edu>
  6. Date: 21 Jul 92 23:37:26 GMT
  7. Sender: root@ucsbcsl.ucsb.edu
  8. Distribution: usa
  9. Organization: Center for Computer Music Research and Composition, UCSB
  10. Lines: 50
  11.  
  12. I have a class in which I overload the = operator:
  13.  
  14. class QueryValue : public QueryLabel {
  15. public:
  16.     QueryValue(const char *, CharCheckFun ccf, LegalValueFun lvf);
  17.     virtual ~QueryValue();
  18.     ...
  19.     void operator = (const QueryValue& rhs);
  20.     ...
  21. };
  22.  
  23. I then define several subclasses derived from this one:
  24.  
  25. class StringValue : public QueryValue {
  26. public:
  27.     StringValue(const char *, const char *, CharCheckFun ccf, LegalValueFun lvf);
  28.     StringValue(const char *value=nil);
  29.     virtual ~StringValue();
  30.     ...
  31. };
  32.  
  33. etc.
  34. The '=' operator is implemented such that any of the derived classes should be
  35. able to be assigned to one another, because I use virtual function calls to
  36. both the rhs and lhs instances in the expression:
  37.  
  38. void
  39. QueryValue::operator = (const QueryValue& rhs) {
  40.     set(rhs.value());
  41. }
  42.  
  43. However, 
  44.  
  45. When I attempted to assign one of the derived class instances to another,
  46. using '=', I got this compiler error:
  47.  
  48. ./request.c:129: assignment not defined for type `StringValue'
  49.  
  50. I looked through Stroustup, but could find no information about how operator
  51. functions are inherited by subclasses.  Why is '=' not defined?  How does this
  52. work??
  53.  
  54. Thanks in advance.
  55.  
  56.  
  57. -- 
  58. Douglas Scott                              (805)893-8352
  59. Center for Computer Music Research and Composition
  60. University of California, Santa Barbara
  61. Internet: (NeXTMail ok)   <doug@foxtrot.ccmrc.ucsb.edu>
  62.