Re: why do constructors return GtkWidget?
- From: Thomas Stover <thomas wsinnovations com>
- To: Emmanuel Touzery <emmanuel touzery free fr>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: why do constructors return GtkWidget?
- Date: Thu, 10 Sep 2009 15:58:16 -0500
Emmanuel Touzery wrote:
It startles me that it doesn't seem to bother people much that all the
widget variables are declared as GtkWidget*.
Well, if you want you can use variables of type GtkWidgetOfTypeX * and
type cast on the call of constructor. You have to type cast back to
GtkWidget * allot, but I've done that sometimes. At least then more of
your mistakes are caught by the compiler instead of g_assert(). Most API
functions work in terms of widgets, while only when you need to do
widget type specific operations do the derived types come into play. In
other object oriented languages perhapses the constructors would return
a derived class instance pointer and let the language work out when a
base class is compatible or not. Here though, once you have an entire
system based around typecasting, you just have to accept the trade offs
of no-nonsense vs learning curve we are fortunate enough to have.
] [Thread Prev