This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: templates, derived classes, and dynamic_cast
- To: Chris Mason <cmason at cmu dot edu>
- Subject: Re: templates, derived classes, and dynamic_cast
- From: Nathan Sidwell <nathan at codesourcery dot com>
- Date: Thu, 16 Mar 2000 10:06:21 +0000
- CC: gcc-bugs at gcc dot gnu dot org, cmason+bio at ash dot rem dot cmu dot edu, post+comp dot lang dot c++ at andrew dot cmu dot edu
- Organization: CodeSourcery, LLC
- References: <38D070F2.E10E8654@cmu.edu>
Chris Mason wrote:
> There's nothing in (the 2 Dec 1999 draft version of) the C++ std which
> directly discusses dynamic_casting of templates. So I can't say for
> sure if this code is or is not correct, as far as the standard is
> concerned.
The behaviour you see is what is expected.
> ah->put(new Derived());
anyholder::put<Derived *&> is instantiated here and creates a
any<Derived *> holder.
> ah->get(b);
anyholder::get<Base *&> is instantiated here. This tries to
do
dynamic_cast <any<Base *> *> (b)
any<Base *> and any<Derived *> are sibling classes separately
derived from anybase. So the dynamic_cast fails.
nathan
--
Dr Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org