Re: Why do constructors return GtkWidget?
- From: Cody Russell <bratsche gnome org>
- To: Javier Jardón <javierjc1982 gmail com>
- Cc: gtk-devel-list <gtk-devel-list gnome org>
- Subject: Re: Why do constructors return GtkWidget?
- Date: Tue, 03 Nov 2009 23:47:51 -0600
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]