This is the mail archive of the
mailing list for the GCC project.
Re: dynamic_cast problem
- From: "corey taylor" <corey dot taylor at gmail dot com>
- To: "ganesh subramonian" <gun_raj at yahoo dot com>, gcc-help at gnu dot org
- Date: Wed, 14 Nov 2007 11:37:21 -0500
- Subject: Re: dynamic_cast problem
- References: <email@example.com> <firstname.lastname@example.org>
On 11/14/07, ganesh subramonian <email@example.com> wrote:
> i am afraid that i couldnt really understand what you
> have written. i am not a compiler writer.
> i would be grateful if you could explain why the
> problem occurs in simpler terms.
I hope this isn't oversimplified or missing the point you're confused about.
The first rule in casting object pointers like that is the two objects
must be related, that is one must be a base class of the other or both
must be the same.
In your case, they both derive from the same class: A, but they do not
derive from each other. The paragraph from the spec is explaining
specifically how the relationship is determined and tested and the
result of each. Because your objects do not meet those criteria, a
NULL is returned upon failure.
Just because two objects might seem like they have the same signature
(both deriving from the same class), they are not considered equal.