Colour constructor


Hi Jules,

Is there is a good reason why:

is declared ‘explicit’ but I can’t see it? I’d like to be able to do something like:

Rather than having to wrap the int in Colour().

BTW I spotted a typo in the Colour docs:

should be:

I copied and pasted this as code without looking too closely and wondered why everything had a strange tint!


Thanks for spotting the typo!

I’m pretty sure there was a good reason why I did that, but the class is quite a few years old now, and I can’t remember what it was… It was probably to avoid some kind of conflict/ambiguity somewhere, though it might well no longer be needed.


Unsure to fully understand your question, but you have to write this :

with the “u” that turns the constant to unsigned.

Hope this helps,


Possibly a fair point but that was just an example, I’m actually returning an unsigned long from a function. With or without the U suffix, Xcode (at least) complains that setColour() doesn’t take an ‘unsigned int’ as an argument.

The point is (I think) that you’d need to write:

…rather than simply

If the declaration

was simply:

you could just call:

and the Colour constructor would be called implicitly (a bit like using a C string where Juce expects a Juce String and more recently a MidiMessage where a MidiBuffer is expected). The ‘explicit’ keyword means the constructor will not be called implicitly.

But as Jules says, he probably had some reason for it which may or may not still be a problem. Often this is where there are ambiguities arising from overloaded functions.


Well I didn’t get it. Now I see your point.