[gtkmm] Replacing dynamic_cast<> with static_cast<> - compiler error.



I'm experimenting with changing the dynamic_cast<>s in the default
signal handlers with static_cast<>s to avoid the
dynamic-cast-during-constructor gcc2.9* bug.

But I'm getting this error:

Atk::Object_Class::children_changed_callback (AtkObject *, unsigned 
int, void *)':
object.cc:229: invalid static_cast from type `Glib::ObjectBase *' to 
type `Atk::Object *'

I can't understand why. I think I remember it being something do with
Multiple Inheritance and/or virtual base classes. Can someone explain it
to me again? I have attached the patch that produces this error.

Here is my code comment, but I don't understand it anymore:
 dnl  We have to use a dynamic_cast because we do not 
 dnl  know the actual type from which to cast up.

I suspect that this is some normal C++ thing. I seem to remember that we
should be able to use static_cast<> in some places and dynamic_cast<> in
others. I think I was just being lazy when writing the code generator.

-- 
Murray Cumming
murrayc usa net
www.murrayc.com
? gtkmm-1.3.kdevprj
? gtkmm-1.3.kdevses
? less_dynamic_casts.patch
? examples/book/combo/Makefile
? examples/book/combo/Makefile.in
? examples/book/combo/combo
? examples/book/dialogs/Makefile
? examples/book/dialogs/Makefile.in
? examples/book/dialogs/simple/Makefile
? examples/book/dialogs/simple/Makefile.in
? examples/book/dialogs/simple/simple
? examples/book/menus/Makefile
? examples/book/menus/Makefile.in
? examples/book/menus/main_menu/Makefile
? examples/book/menus/main_menu/Makefile.in
? examples/book/menus/main_menu/main_menu
? examples/book/menus/popup/Makefile
? examples/book/menus/popup/Makefile.in
? examples/book/menus/popup/popup
? examples/book/signals/Makefile
? examples/book/signals/Makefile.in
? examples/book/signals/custom/Makefile
? examples/book/signals/custom/Makefile.in
? examples/book/signals/custom/example
? gtk/gtkmm/separatormenuitem.cc
? gtk/gtkmm/separatormenuitem.h
? gtk/gtkmm/treerowreference.cc
? gtk/gtkmm/treerowreference.h
? gtk/gtkmm/private/separatormenuitem_p.h
? gtk/gtkmm/private/treerowreference_p.h
? pango/pangomm/attributes.cc
? pango/pangomm/attributes.h
? pango/pangomm/attriter.cc
? pango/pangomm/attriter.h
? pango/pangomm/color.cc
? pango/pangomm/color.h
? pango/pangomm/glyph.cc
? pango/pangomm/glyph.h
? pango/pangomm/item.cc
? pango/pangomm/item.h
? pango/pangomm/language.cc
? pango/pangomm/language.h
? pango/pangomm/layoutrun.cc
? pango/pangomm/layoutrun.h
? pango/pangomm/rectangle.cc
? pango/pangomm/rectangle.h
? pango/pangomm/private/attributes_p.h
? pango/pangomm/private/attriter_p.h
? pango/pangomm/private/color_p.h
? pango/pangomm/private/glyph_p.h
? pango/pangomm/private/item_p.h
? pango/pangomm/private/language_p.h
? pango/pangomm/private/layoutrun_p.h
? pango/pangomm/private/rectangle_p.h
? tests/child_widget/Makefile
? tests/child_widget/Makefile.in
? tests/child_widget2/Makefile
? tests/child_widget2/Makefile.in
? tests/child_widget_managed/Makefile
? tests/child_widget_managed/Makefile.in
? tests/child_widget_managed/test
? tests/delete_cpp_child/Makefile
? tests/delete_cpp_child/Makefile.in
? tests/dialog_deletethis/Makefile
? tests/dialog_deletethis/Makefile.in
? tests/glibmm_value/Makefile
? tests/glibmm_value/Makefile.in
? tests/refcount_dialog/Makefile
? tests/refcount_dialog/Makefile.in
Index: tools/m4/signal.m4
===================================================================
RCS file: /cvs/gnome/gtkmm-root/tools/m4/signal.m4,v
retrieving revision 1.18
diff -u -p -r1.18 signal.m4
--- tools/m4/signal.m4	19 Jul 2002 11:21:31 -0000	1.18
+++ tools/m4/signal.m4	18 Sep 2002 10:08:20 -0000
@@ -129,7 +129,7 @@ $4 __CPPNAME__`'_Class::$2_callback`'($5
 dnl  We cast twice to allow for multiple-inheritance casts, which might 
 dnl  change the value.  We have to use a dynamic_cast because we do not 
 dnl  know the actual type from which to cast up.
-  CppObjectType *const obj = dynamic_cast<CppObjectType*>(
+  CppObjectType *const obj = static_cast<CppObjectType*>(
       Glib::ObjectBase::_get_current_wrapper`'((GObject*)$8));
 
 _IMPORT(SECTION_CHECK)
Index: tools/m4/vfunc.m4
===================================================================
RCS file: /cvs/gnome/gtkmm-root/tools/m4/vfunc.m4,v
retrieving revision 1.13
diff -u -p -r1.13 vfunc.m4
--- tools/m4/vfunc.m4	3 Jul 2002 10:58:11 -0000	1.13
+++ tools/m4/vfunc.m4	18 Sep 2002 10:08:20 -0000
@@ -22,7 +22,7 @@ $4 __CPPNAME__`'_Class::$2_vfunc_callbac
 dnl  We cast twice to allow for multiple-inheritance casts, which might 
 dnl  change the value.  We have to use a dynamic_cast because we do not 
 dnl  know the actual type from which to cast up.
-  CppObjectType *const obj = dynamic_cast<CppObjectType*>(
+  CppObjectType *const obj = static_cast<CppObjectType*>(
       Glib::ObjectBase::_get_current_wrapper`'((GObject*)$8));
 
 _IMPORT(SECTION_CHECK)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]