Re: Why do constructors return GtkWidget?



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.



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