Re: GdkColor weird type? Why not pointer like GtkWidget*....



> From: Christian Seberino <seberino spawar navy mil>
>
> I've seen examples in GTK+ books where GdkColor widgets
> are not declared to be pointers   (GdkColor* myColor;)
> but instead declared like this... (GdkColor  myColor;)
>
> I don't know if this begins to explain g++ not liking
> this initialization or not....
>
> GdkColor Color:myStaticColor = (GdkColor 0); // *won't work!!*
>
> *only* this works...
>
> GdkColor Color:myStaticColor = {0}; // *won't work!!*
>
> Is GdkColor some weird type or something?? Do you
> know why {0} works but not "(GdkColor) 0"???

(GdkColor) 0 doesn't work because it's not a pointer.

It really an extern "C" struct with four members.
Since it's extern "C", you need to initialize it
in the proper C (_not_ C++) way. For a struct in C,
you provide an initialization list for the members,
e.g.

GdkColor color = {0, 0, 0, 0};

If you provide fewer initializers than there are members,
the last initializer is used to initialize all remaining
members, so

GdkColor color = {0};

is equivalent.

Just because you're initializing GdkColor in C++ doesn't
mean you can treat it like a C++ class. It's still a
C struct.

Ron Steinke



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