Topic: dynamic_cast<T> implementation..


Author: jbuck@Synopsys.COM (Joe Buck)
Date: 1995/10/21
Raw View
"Michael McCarty" <mikem@eai.com> writes:
>How exactly is dynamic_cast<T> supposed to be implemented in the compiler?

In a manner similar to virtual functions.  dynamic_cast only works for
types that have virtual functions and is not permitted on other types.

>It seems to me that the only way to implement this is to attach a type
>'pointer' to every object instantiated, similar to virtual function pointer
>tables.

Right, except that you re-use the pointer you already have, adding a bit
more stuff to the existing virtual function table.  The virtual function
table is already a type pointer, in effect.  There's no additional
time penalty for code that doesn't use dynamic_cast.


--
-- Joe Buck  <jbuck@synopsys.com> (not speaking for Synopsys, Inc)
Anagrams for "information superhighway": Enormous hairy pig with fan
      A rough whimper of insanity


---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]