home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c++
- Path: sparky!uunet!taumet!steve
- From: steve@taumet.com (Steve Clamage)
- Subject: Re: Problems casting an object derived from a virtual base class.
- Message-ID: <1992Jul21.171019.10290@taumet.com>
- Organization: TauMetric Corporation
- References: <1992Jul19.151041.5458@taumet.com> <1992Jul20.153254.5025@cadsun.corp.mot.com>
- Date: Tue, 21 Jul 1992 17:10:19 GMT
- Lines: 46
-
- shang@corp.mot.com (David (Lujun) Shang) writes:
-
- >In article <1992Jul19.151041.5458@taumet.com> steve@taumet.com (Steve Clamage)
- >> The proposals have been to allow runtime type information only for types
- >> with virtual functions. (Some questions were raised this past week at the
- >> C++ meeting about type information for built-in types, but that doesn't
- >> apply to this discussion.) Type information would then be tied to the
- >> virtual table for the type. There would be no space overhead in any
- >> object. (The type information is per class type, not per object.)
- >>
-
- >You still need reverse information for classes with virtual functions for a
- >proper downcast from a virtual base to the derived.
-
- That is part of the RTTI, not necessarily stored in the object. Example:
-
- class b1 { ... };
- class b2 { ... };
- class d : virtual public b1, virtual public b2 { ... };
- class e : virtual public b1, public d { ... };
-
- b1 *p = ...;
-
- Variable p will point to some object of type b1, d, or e. To cast from
- b1* to e*, we use a "checked cast", which looks up the type information
- at run time. The data needed for the conversion is part of the type
- info. Typically, the virtual base is contiguous with the rest of the
- object, so only an offset is needed. Non-contiguous virtual bases
- cause a number of problems which the implementation would have to
- solve, including this problem.
-
- We don't need to specify in the standard something which turns out to
- be perfectly efficient for any conceivable implementation. The
- standard does not require virtual tables or pointers to them, for
- example, but merely allows them. Less-efficient implementations are
- possible and allowable. More efficient implementations might be
- possible with smarter compilers and linkers, and would likewise be
- allowable.
-
- An implementation which required reverse pointers in objects would
- still be allowable, but users would probably vote with their purchase
- orders for other implementations.
- --
-
- Steve Clamage, TauMetric Corp, steve@taumet.com
- Vice Chair, ANSI C++ Committee, X3J16
-