I'm a little confused on cast_dynamic and cast_static in Glib::RefPtr.
- From: Tao Wang <dancefire gmail com>
- To: gtkmm-list gnome org
- Subject: I'm a little confused on cast_dynamic and cast_static in Glib::RefPtr.
- Date: Wed, 11 Aug 2010 13:15:29 +1000
Hi,
It might be a basic C++ question, I'm not sure that I should asked here, but I'm a little confused on these 2 cast:
RefPtr<Derived>::cast_dynamic(ptr_base);
RefPtr<Derived>::cast_static(ptr_base);
Say, Gtk::Action is inherited from Gtk::Object, and I get RefPtr<Gtk::Object>, and I need to cast to RefPtr<Gtk::Action>. Which one should I use?
I think both static_cast<> and dynamic_cast<> can handle the cast between classes in the class hierarchy. But dynamic_cast do more for the RTTI type checking during the run time. However, if Gtk::Action is not inherited from Gtk::Object, (and no conversion function available between them), the code cannot be compiled successfully. So, it seems that it not necessary to use cast_dynamic() here.
So, is it ok that I use cast_static() for casting from Gtk::Object to Gtk::Action? and what is the case that we should use cast_dynamic()? Thank you in advance.
--
Regards
Tao Wang
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]