String << operator missing for unsigned short

I’ve found that an unsigned short value passed to the String operator << ends up treated like a char.
I also think that completing << operators for ‘long’ and ‘unsigned long’ values could be a good idea.

Yes, good request!

Arghhh… Can you revert this change ?
It conflicts with juce_wchar (method already defined) type on my compiler.
wchar == unsigned short when you compile unicode built.

Maybe a define could be good ?

Which compiler is that? Surely it’s perfectly ok to have two methods that take the same sized value if they’re presented as different typedefs… You might need to do an explicit cast when you use them, but I can’t see why it’d fail to compile.

Plain old microsoft Visual C++ 6 compiler.

BTW try this under gcc:

typedef int mytype;
class A
   void foo(int) {}
   void foo(mytype) {}  // fatal error: method already defined

Hmm - yes, that does fail in gcc too… I always assumed the compiler could distinguish between typedefs like it does other types, but I guess it must just treat them as aliases. That’s a bit lame, really.

Ok, well I’m just going to scrap that << operator, it’s too messy to try to deal with this in any other way. If anyone needs to use it, they can easily just cast their value to an int.

…hang on - in other compilers, juce_wchar is a wchar_t, which is an int. Why doesn’t that clash with the << operator?

… ah, the compiler’s treating it as a special case. I guess that’s why it compiles ok in VC7, where it’s also an unsigned short. Only the crappy old VC6 compiler is actually using a typedef for wchar_t.

using explicit keyword do not solve the issue ?

‘explicit’ is only for use with constructors, I think.


What about the other way, I mean drop the wchar_t version, and provide both int and short int type ?
I guess it’ll work everywhere.

I think being able to append a character to a string is a bit more useful than an unsigned short!

Yes in theory. In practice, as wchar is either an int or a unsigned short, it’ll use whatever overload (int or unsigned short).
Unless I’m mistaken in the operator function, does the “<< operator(wchar)” concatenate the char ?
I initially though it was a convert the integral type to a string version (that is String()<<(wchar)32 == “32” and not " ")