Cyclic Dependencies

Derek Parnell derek at psych.ward
Tue Dec 9 02:06:42 PST 2008


On Tue, 09 Dec 2008 01:26:29 -0600, Ellery Newcomer wrote:


> 
> wchar[] w = (true)? "true":"false";
> 
> --> Error: cannot implicitly convert expression ("true") of type char[] 
> to wchar[]
> 
> or should it be reported as a bug?

It is not a bug. A string literal such as "true" is a char[] type (UTF8),
and the compiler will not implicitly convert UTF8 to UTF16 (wchar[]).

You can tell the compiler that the string literal is meant to be UTF16 by
added the suffix 'w' to the literal ... "true"w, and in that way no
conversion is required.

If for some reason you did want a run-time conversion then this should work
...


wchar[] w = std.utf.toUTF16((true)? "true":"false");

-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell


More information about the Digitalmars-d-learn mailing list