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



On 03/17/2009 10:33 AM, Paulo Flabiano Smorigo wrote:
Hello,

What can I do to solve the following error? I need to use a different
kind of pointer?

The code:
Gtk::ToggleButton btnOK;
Gtk::Widget *ptrElement = NULL;

ptrElement =&btnOK;

ptrElement->set_active(true);

The error:
error: ‘class Gtk::Widget’ has no member named ‘set_active’


But why do you want to do that, assigning a pointer to a stack object, given that as soon as you leave the scope the pointer will be invalid.

Unlike the other said, you'd better use static_cast<> because at that point you do know that ptrElement points to a Gtk::ToggleButton.

And no it can't guess. C++ is a statically typed, which means that it needs to know at compile time about the method.

Hub


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