Re: Question about type casting.



DC A wrote:
[...]

Why we cast for the first argument of this function but not the second one?

   It seems a little wierd, but eventually you find that its just easier to
generalize where you can:

/* gtk_button_new & gtk_vbox_new return `GtkWidget *',
 * not `GtkButton *'
 */
GtkWidget *vbox   = gtk_vbox_new (FALSE, 0);
GtkWidget *button = gtk_button_new ();

/* Here we cast our `GtkWidget *vbox' to GTK_BOX to suit
 * the api, most gtk functions take GtkWidget arguments
 * (well, at least most container implementations do), so
 * its just easier to declare every widget as `GtkWidget *'
 * and not its subclass.
 */
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);

Cheers,
                              -Tristan



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