home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / std / cplus / 901 < prev    next >
Encoding:
Text File  |  1992-07-21  |  2.4 KB  |  57 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: Problems casting an object derived from a virtual base class.
  5. Message-ID: <1992Jul21.171019.10290@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <1992Jul19.151041.5458@taumet.com> <1992Jul20.153254.5025@cadsun.corp.mot.com>
  8. Date: Tue, 21 Jul 1992 17:10:19 GMT
  9. Lines: 46
  10.  
  11. shang@corp.mot.com (David (Lujun) Shang) writes:
  12.  
  13. >In article <1992Jul19.151041.5458@taumet.com> steve@taumet.com (Steve Clamage)  
  14. >> The proposals have been to allow runtime type information only for types
  15. >> with virtual functions.  (Some questions were raised this past week at the
  16. >> C++ meeting about type information for built-in types, but that doesn't
  17. >> apply to this discussion.)  Type information would then be tied to the
  18. >> virtual table for the type.  There would be no space overhead in any
  19. >> object.  (The type information is per class type, not per object.)
  20. >> 
  21.  
  22. >You still need reverse information for classes with virtual functions for a  
  23. >proper downcast from a virtual base to the derived.
  24.  
  25. That is part of the RTTI, not necessarily stored in the object.  Example:
  26.  
  27. class b1 { ... };
  28. class b2 { ... };
  29. class d : virtual public b1, virtual public b2 { ... };
  30. class e : virtual public b1, public d { ... };
  31.  
  32. b1 *p = ...;
  33.  
  34. Variable p will point to some object of type b1, d, or e.  To cast from
  35. b1* to e*, we use a "checked cast", which looks up the type information
  36. at run time.  The data needed for the conversion is part of the type
  37. info.  Typically, the virtual base is contiguous with the rest of the
  38. object, so only an offset is needed.  Non-contiguous virtual bases
  39. cause a number of problems which the implementation would have to
  40. solve, including this problem.
  41.  
  42. We don't need to specify in the standard something which turns out to
  43. be perfectly efficient for any conceivable implementation.  The
  44. standard does not require virtual tables or pointers to them, for
  45. example, but merely allows them.  Less-efficient implementations are
  46. possible and allowable.  More efficient implementations might be
  47. possible with smarter compilers and linkers, and would likewise be
  48. allowable.
  49.  
  50. An implementation which required reverse pointers in objects would
  51. still be allowable, but users would probably vote with their purchase
  52. orders for other implementations.
  53. -- 
  54.  
  55. Steve Clamage, TauMetric Corp, steve@taumet.com
  56. Vice Chair, ANSI C++ Committee, X3J16
  57.