Re: Why do constructors return GtkWidget?

On Tue, 2009-11-03 at 23:47 -0600, Cody Russell wrote:
> On Wed, 2009-11-04 at 06:23 +0100, Javier Jardón wrote:
> > The question: why is it normal for GTK widget "constructors" to return
> > GtkWidget and not their real type?
> > 
> > For instance I would expect:
> > 
> >    gtk_menu_item_new ()
> > 
> > To return GtkMenuItem*. But it doesn't, it returns GtkWidget*.
> > IMHO is much clear that constructors return their real type, instead
> > GtkWidget. But maybe there is a technical reason for this. 
> Almost invariably you're going to be doing something with the return
> value as a GtkWidget, such as calling gtk_widget_show() on it or packing
> it into a container.  If that method above returned GtkMenuItem* then
> that guarantees a cast, whereas if it returns a GtkWidget* then it may
> just get packed into a container and that's the end of it.

What Cody is trying to say is that the pointer type returned is a
convention for convenience, since C doesn't have the idea of type

If you were to call G_OBJECT_TYPE() it would return GTK_TYPE_MENU_ITEM.

Danielle Madeley

Collabora Ltd., Melbourne, Australia

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