On 08/21/2011 10:40 AM, Evan Laforge wrote: >> Creating its own type for color is ok with a typedef, but changing it from >> an underlying uint32 wold be insanely inefficient, considering that a color >> vaue is needed in every graphics call. > > typedef doesn't actually create a new type. A real type should be > just as efficient as a number, and C++ was specifically designed to > support this: > > class Color { > private: > uint32 val; > public: > uint32 argb() const { return val; } // to pass to other libraries, OS, etc. > ... // methods that apply to colors, not numbers > } > > As far as I can tell, there are no cons, and plenty of pros.
I believe modern compilers are fixed, but initially some C++ compilers were really stupid and turned this into vastly less efficient code than when it was an integer. Generally I feel that a typedef is sufficient. It does not prevent misuse, but it makes the function prototypes clear. It also means that the user can type 0xaarrggbb directly into the code and it works. Qt is really annoying that I always have to look up the converter function. _______________________________________________ fltk-dev mailing list fltk-dev@easysw.com http://lists.easysw.com/mailman/listinfo/fltk-dev