home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!decwrl!pa.dec.com!lattanzi
- From: lattanzi@wsl.dec.com (Len Lattanzi)
- Subject: Re: Downcasting (was: Re: run-time type checking)
- Message-ID: <1992Aug13.074232.28627@PA.dec.com>
- Keywords: polymorphism, RTTI, downcasts.
- Sender: news@PA.dec.com (News)
- Organization: Western Software Lab
- References: <1992Aug8.152913.20167@mole-end.matawan.nj.us> <1992Aug9.221309.15259@ucc.su.OZ.AU> <9222518.29381@mulga.cs.mu.OZ.AU>
- Date: Thu, 13 Aug 92 07:42:32 GMT
- Lines: 31
-
- In article <9222518.29381@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
- :
- :This is a good idea.
- :In particular, it seems that this technique much reduces the attraction of
- :the current proposal to allow downcasting, because users can achieve virtually
- :the same effect themselves - they just have to make the interface explicit.
- :
- :For example
- :
- : class Base {
- : ...
- : operator Derived1*() { return 0; }
- Better make that virtual operator Derived1*()
- : };
- :
- : class Derived1() {
- : ...
- : operator Derived1*() { return this; }
- : };
- :
- : Base *base_p;
- : ...
- : Derived1 *derived1_p = (Derived *) *base_p;
- : if (derived_p) { ... }
- :
- Biggest drawback is that Base must know about every derived class and
- provide a virtual type conversion. But it is a usable poor-man's RTTI.
-
- --
- \
- Len Lattanzi (Migration Software Systems Ltd 408 452 0527) <len@migration.com>
-