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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!mole-end!mat
  3. From: mat@mole-end.matawan.nj.us
  4. Subject: Re: Downcasting (was: Re: run-time type checking)
  5. Message-ID: <1992Aug14.165432.14403@mole-end.matawan.nj.us>
  6. Keywords: polymorphism, RTTI, downcasts.
  7. Organization: :
  8. References: <1992Aug5.110132.8756@ucc.su.OZ.AU> <9222518.29381@mulga.cs.mu.OZ.AU>
  9. Date: Fri, 14 Aug 1992 16:54:32 GMT
  10. Lines: 36
  11.  
  12. In article <9222518.29381@mulga.cs.mu.OZ.AU>, fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
  13. > maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  14.  
  15. > >There are other ways than tagged pointers to make downcasting
  16. > >sound. One might be to declare the derived classes that you want
  17. > >to downcast to in the base class FROM which you want to downcast:
  18.  
  19. > >    class Base {
  20. > >        ....
  21. > >        operator Derived1*() =0;
  22. > >        operator Derived2*() =0;
  23. > >    };
  24.  
  25. > This is a good idea.
  26. > In particular, it seems that this technique much reduces the attraction of
  27. > the current proposal to allow downcasting, because users can achieve virtually
  28. > the same effect themselves - they just have to make the interface explicit.
  29.  
  30. >     class Derived1() {
  31. >         ...
  32. >         operator Derived1*() { return this; }
  33. >     };
  34.  
  35. The problem with this is that it requires explicit functions all over
  36. the place.  It swells the interfaces (trust me, I've seen it used, even
  37. suggested it as the best possible in C++ today), swells the vtables, may
  38. thereby interefere with some language implementations, and makes the
  39. code brittle.
  40.  
  41. But I like the idea of declarations in the derived type permitting or
  42. blocking an RTTI-based conversion.
  43. -- 
  44.  (This man's opinions are his own.)
  45.  From mole-end                Mark Terribile
  46.  
  47.  mat@mole-end.matawan.nj.us, Somewhere in Matawan, NJ
  48.