Re: why do constructors return GtkWidget?



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.




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