home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12297 < prev    next >
Encoding:
Text File  |  1992-08-12  |  1.4 KB  |  44 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!decwrl!pa.dec.com!lattanzi
  3. From: lattanzi@wsl.dec.com (Len Lattanzi)
  4. Subject: Re: Downcasting (was: Re: run-time type checking)
  5. Message-ID: <1992Aug13.074232.28627@PA.dec.com>
  6. Keywords: polymorphism, RTTI, downcasts.
  7. Sender: news@PA.dec.com (News)
  8. Organization: Western Software Lab
  9. References: <1992Aug8.152913.20167@mole-end.matawan.nj.us> <1992Aug9.221309.15259@ucc.su.OZ.AU> <9222518.29381@mulga.cs.mu.OZ.AU>
  10. Date: Thu, 13 Aug 92 07:42:32 GMT
  11. Lines: 31
  12.  
  13. In article <9222518.29381@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
  14. :
  15. :This is a good idea.
  16. :In particular, it seems that this technique much reduces the attraction of
  17. :the current proposal to allow downcasting, because users can achieve virtually
  18. :the same effect themselves - they just have to make the interface explicit.
  19. :
  20. :For example
  21. :
  22. :    class Base {
  23. :        ...
  24. :        operator Derived1*() { return 0; }
  25. Better make that virtual operator Derived1*()
  26. :    };
  27. :
  28. :    class Derived1() {
  29. :        ...
  30. :        operator Derived1*() { return this; }
  31. :    };
  32. :
  33. :    Base *base_p;
  34. :    ...
  35. :    Derived1 *derived1_p = (Derived *) *base_p;
  36. :    if (derived_p) { ... }
  37. :
  38. Biggest drawback is that Base must know about every derived class and
  39. provide a virtual type conversion. But it is a usable poor-man's RTTI.
  40.  
  41. --
  42. \
  43.  Len Lattanzi (Migration Software Systems Ltd 408 452 0527) <len@migration.com>
  44.