home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11653 < prev    next >
Encoding:
Internet Message Format  |  1992-07-22  |  1.8 KB

  1. Xref: sparky comp.lang.c++:11653 comp.std.c++:969
  2. Path: sparky!uunet!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!yale!mintaka.lcs.mit.edu!ai-lab!life.ai.mit.edu!tmb
  3. From: tmb@arolla.idiap.ch (Thomas M. Breuel)
  4. Newsgroups: comp.lang.c++,comp.std.c++
  5. Subject: Re: run-time type checking (was: Re: Covariant Types in Derived Classes)
  6. Message-ID: <TMB.92Jul28122857@arolla.idiap.ch>
  7. Date: 28 Jul 92 16:28:57 GMT
  8. References: <9220719.894@mulga.cs.mu.OZ.AU> <1992Jul27.161441.7898@cadsun.corp.mot.com>
  9. Sender: news@ai.mit.edu
  10. Reply-To: tmb@idiap.ch
  11. Followup-To: comp.lang.c++
  12. Organization: IDIAP (Institut Dalle Molle d'Intelligence Artificielle
  13.     Perceptive)
  14. Lines: 32
  15. In-reply-to: shang@corp.mot.com's message of 27 Jul 92 16:14:41 GMT
  16.  
  17. In article <1992Jul27.161441.7898@cadsun.corp.mot.com> shang@corp.mot.com (David (Lujun) Shang) writes:
  18.  
  19.    I may write:
  20.  
  21.        bestow_on (victor).
  22.  
  23.    where bestow_on is a function which gives a female peer to the victor (suppose  
  24.    only the male can fight):
  25.  
  26.       void bestow_on (Animal * victor)
  27.       {    Animal * f = new typeof(*victor)(female));
  28.            // suppose we need do some work for the female here
  29.            // ...
  30.            victor->mate(f); // type inference here ensure that f is the 
  31.                 // correct type and the downcast is safe
  32.       };
  33.  
  34.    here both RTTI and downcast are needed, though I did not write an explicit  
  35.    downcast which is actually happen in the call of "mate":
  36.  
  37. They are not "needed". You can simply make "bestow_on" a virtual
  38. member function of "Animal" and have it do the right thing for each
  39. kind of animal.
  40.  
  41. Is this pedestrian? You bet it is, but no more so than many other
  42. aspects of C++ (e.g., memory management has to be handled on a
  43. per-class basis, value semantics have to re-implemented on a
  44. case-by-case basis, etc.).
  45.  
  46. If you think you really need those features, there is always CLOS...
  47.  
  48.                     Thomas.
  49.