Re: How to use specific methods with a generic widget pointer?



Paulo Flabiano Smorigo a écrit :
Hi Guillaume,

Thanks for the fast reply...

I know that the Gtk::Widget don't have the set_active() member but as
it is pointing to a ToggleButton widget, isn't it possible to use the
method?

I there a someway to make the pointer accept the method?

You can cast the pointer to obtain a "Gtk::ToggleButton *" using "dynamic_cast" c++ operator. The code may look like this :

dynamic_cast< Gtk::ToggleButton* >( ptrElement )->set_active(true);

But, you must be aware that "dynamic_cast" will return a null pointer if ptrElement does not point to a Gtk::ToggleButton (or derived) instance. You should then check the pointer prior call "set_active".

Guillaume


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