Re: why do constructors return GtkWidget?
- From: Tristan Van Berkom <tvb gnome org>
- To: Emmanuel Touzery <emmanuel touzery free fr>
- Cc: gtk-app-devel-list gnome org, Murray Cumming <murrayc murrayc com>
- Subject: Re: why do constructors return GtkWidget?
- Date: Tue, 8 Sep 2009 22:02:50 -0400
On Tue, Sep 8, 2009 at 12:54 PM, Emmanuel
Touzery<emmanuel touzery free fr> wrote:
Hi,
Whatever type is returned, you'll have to do lots of casts, so whatever
convention is used, there's no avoiding that. And returning GtkWidget*
is just the current convention.
I personally would prefer correct types to be used in the API, just to
show exactly what type to expect at runtime. But that's a separate
issue.
Thank you for the answer. If it doesn't make a technical difference I think
returning the actual type would be much more useful, for documentation
purposes. In the case of gtk_menu_shell_append() from the prototype you
would think that it can take any GtkWidget and only the comment tells you
that only GtkMenuItem* will do.
There is a technical difference when writing GTK+ code in C; for instance
its quite often that you will access methods on the GtkWidgetClass
(like show()/hide()/set_sensitive() etc), also many other apis take GtkWidget *
argument, namely GtkContainer apis which operate on child widgets.
From this standpoint its alot more convenient to cast all your widget variables
as GtkWidget * (this way you keep casting to a minimum in your code) so GTK+
is only helping you by returning GtkWidget *, if only for a simple and
practical
reason to save you a little casting/typing.
Cheers,
-Tristan
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]