I'm a little confused on cast_dynamic and cast_static in Glib::RefPtr.


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:


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.

Tao Wang

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