Re: [gtkmm] Replacing dynamic_cast<> with static_cast<> - compiler error.
- From: Nick Huxley <nick anvil co uk>
- To: Murray Cumming <murrayc usa net>
- Cc: Paulo Pinto <pjmlp progtools org>, gtkmm-main <gtkmm-list gnome org>
- Subject: Re: [gtkmm] Replacing dynamic_cast<> with static_cast<> - compiler error.
- Date: Wed, 18 Sep 2002 12:23:14 +0100 (BST)
On 18 Sep 2002, Murray Cumming wrote:
> On Wed, 2002-09-18 at 12:15, Paulo Pinto wrote:
> > Sorry for the naive question, but what is
> > the relation between `Glib::ObjectBase *'
> > and `Atk::Object *' ?
>
> http://www.gtkmm.org/gtkmm2/reference/html/classAtk_1_1Object.html
>
> It's a base class. Actually it's a virtual base class. I think I have
> learnt that static_cast<> can never be used to cast down from a virtual
> base class, so none of these dynamic_cast<>s can be changed to
> static_cast<>s.
>
Unfortunately you are right. Since we're dealing with pointers for the
polymorphism then the compiler can't know what will be passed in so a
static_cast cannot be used. The dynamic_cast checks at run time and will
throw an exception if the cast cannot be meaningfully performed.
Nick
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]