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