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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!darwin.sura.net!uvaarpa!murdoch!virginia.edu!gs4t
  3. From: gs4t@virginia.edu (Gnanasekaran Swaminathan)
  4. Subject: Re: Overloaded operators and inheritance
  5. Message-ID: <1992Jul22.163110.3289@murdoch.acc.Virginia.EDU>
  6. Sender: usenet@murdoch.acc.Virginia.EDU
  7. Reply-To: gs4t@virginia.edu (Gnanasekaran Swaminathan)
  8. Organization: University of Virginia
  9. References:  <5354@ucsbcsl.ucsb.edu>
  10. Distribution: usa
  11. Date: Wed, 22 Jul 1992 16:31:10 GMT
  12. Lines: 46
  13.  
  14. doug@foxtrot.ccmrc.ucsb.edu (Douglas Scott) writes:
  15. > class QueryValue : public QueryLabel {
  16. > public:
  17. >     ...
  18. >     void operator = (const QueryValue& rhs);
  19. >     ...
  20. > };
  21. > class StringValue : public QueryValue {
  22. > public:
  23. >     virtual ~StringValue();
  24. >     ...
  25. > };
  26. > The '=' operator is implemented such that any of the derived classes should be
  27. > able to be assigned to one another, because I use virtual function calls to
  28. > both the rhs and lhs instances in the expression:
  29. > void
  30. > QueryValue::operator = (const QueryValue& rhs) {
  31. >     set(rhs.value());
  32. > }
  33. > However, 
  34. > When I attempted to assign one of the derived class instances to another,
  35. > using '=', I got this compiler error:
  36. >
  37. > ./request.c:129: assignment not defined for type `StringValue'
  38. > I looked through Stroustup, but could find no information about how operator
  39. > functions are inherited by subclasses.  Why is '=' not defined?  How does this
  40. > work??
  41.  
  42. First, operator = (assignment operator)  is not inherited by
  43. the derived classes. But, if you don't define an assignment
  44. operator in a class, a default assignment operator will be
  45. generated unless the class has a const member, a reference
  46. member, or a member or a base class with a private operator =
  47.  
  48. It appears that your compiler is not able to generate a default
  49. assignment operator for class StringValue because of one
  50. of the reasons listed above. 
  51.  
  52. ARM has a table on p. 306 that gives a summary of the characteristics
  53. of operators and other functions. Perhaps, Stroustrup should include
  54. that table in his book.
  55.  
  56. -Sekar
  57.