🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2280

Re: dynamic_cast<T> implementation...

#2280
From: Michael Cook
Date: Sun, 22 Oct 1995 22:54
38 lines
1713 bytes
>>>>> "JM" == Jason Merrill <jason@cygnus.com> writes:

>>>>> Michael McCarty <mikem@eai.com> writes:
 >> How exactly is dynamic_cast<T> supposed to be implemented in the compiler?

 >> 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.

 >> Tell me it ain't so...

 JM> It ain't so.  Dynamic typing is only supported for polymorphic types --
 JM> classes with virtual functions.  The RTTI pointer goes into the vtable in
 JM> all implementations I know about.

What if I use `dynamic_cast' where `static_cast' would be sufficient?  Is the
type /still/ required to be polymorphic?  For example, given this:

 struct B {};
 struct D : B {};
 D* d;

is this expression valid?

 dynamic_cast<B*>(d)

(Why would I write such code?  Well, the types `B' and `D' might have been
parameters to a template in which I did not want to assume the use of
`static_cast' would be proper.)

Michael.


---
[ 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. ]
Technical Details
Message-ID: <r4rb05s7jj.fsf@pluto.cognex.com>
Path: arc1-ca.pugleaf.net!newsxfer.itd.umich.edu!agate!agate!Matt
References: <9510191610.ZM21213@yosemite.eai.com> <u9hh141x8p.fsf@yorick.cygnus.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!newsxfer.itd.umich.edu!agate!agate!Matt
From: Michael Cook <mcook@cognex.com>
Newsgroups: comp.std.c++
Subject: Re: dynamic_cast<T> implementation...
Date: 22 Oct 1995 22:54:29 GMT
Organization: Cognex Corporation, Natick, Massachusetts
Approved: Matt@Austern
Message-ID: <r4rb05s7jj.fsf@pluto.cognex.com>
References: <9510191610.ZM21213@yosemite.eai.com>
 <u9hh141x8p.fsf@yorick.cygnus.com>
NNTP-Posting-Host: austern.hip.berkeley.edu