home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / cplus / 16036 < prev    next >
Encoding:
Text File  |  1992-11-10  |  2.0 KB  |  48 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!mcsun!news.funet.fi!network.jyu.fi!sakkinen
  3. From: sakkinen@jyu.fi (Markku Sakkinen)
  4. Subject: Re: Casting to an object of a derived class
  5. Message-ID: <1992Nov10.103449.18958@jyu.fi>
  6. Organization: University of Jyvaskyla, Finland
  7. References: <VANDER.92Nov2153247@vancouver.stars.flab.Fujitsu.co.jp> <rmartin.721099675@thor>
  8. Date: Tue, 10 Nov 1992 10:34:49 GMT
  9. Lines: 37
  10.  
  11. In article <rmartin.721099675@thor> rmartin@thor.Rational.COM (Bob Martin) writes:
  12. > ...
  13. >This is one of the difficulties with contravariant return types.  It
  14. >would sometimes be very nice if a member function could return a
  15. >pointer or reference to the most derived object, rather than to the
  16. >base.  However, the language does not support this feature.
  17.  
  18. Of course, if the return type is a pointer or reference to a class,
  19. the derived-class function _can_ return a reference or pointer
  20. to a derived-class object.  Virtual functions will work correctly.
  21. The big problem remains that only members declared in the original
  22. return-type class can be denoted.
  23.  
  24. >It will, soon, support covariant return types, but these will require
  25. >that each derived class repeat the function declaration with the new
  26. >return type.
  27.  
  28. Of course they must do that:  how should the compiler or anybody
  29. know otherwise that there is supposed to be a new return type?
  30.  
  31. Even if this becomes true, the above problem goes away only in the case
  32. where it is statically known that indeed the function of the derived class
  33. will be invoked.  The absence of run-time type information makes
  34. covariant return types a less powerful feature in C++ than in other
  35. OO languages.
  36.  
  37. > ...
  38.  
  39. ----------------------------------------------------------------------
  40. Markku Sakkinen (sakkinen@jytko.jyu.fi)
  41.        SAKKINEN@FINJYU.bitnet (alternative network address)
  42. Department of Computer Science and Information Systems
  43. University of Jyvaskyla (a's with umlauts)
  44. PL 35
  45. SF-40351 Jyvaskyla (umlauts again)
  46. Finland
  47. ----------------------------------------------------------------------
  48.