March 03, 2005 String matching both char & wchar in std.stream.stdout.write | ||||
---|---|---|---|---|
| ||||
For the following code: #import std.stream; #void main() #{ # std.stream.stdout.write("There is no spoon"); #} I get this error: StreamWriteTest.d(5): function std.stream.Stream.write overloads void(char[]s) and void(wchar[]s) both match argument list for write Is there a clean way to fix this? Do I have to cast this string? -Kramer |
March 03, 2005 Re: String matching both char & wchar in std.stream.stdout.write | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kramer | On Thu, 3 Mar 2005 22:48:24 +0000 (UTC), Kramer <Kramer_member@pathlink.com> wrote: > For the following code: > > #import std.stream; > > #void main() > #{ > # std.stream.stdout.write("There is no spoon"); > #} > > I get this error: StreamWriteTest.d(5): function std.stream.Stream.write > overloads void(char[]s) and void(wchar[]s) both match argument list for write > > Is there a clean way to fix this? Do I have to cast this string? Yes. Possible solutions (previously suggested) 0- Do nothing, cast is sufficient. 1- Allowing a prefix to the string i.e. > # std.stream.stdout.write(w"There is no spoon"); (denoting that it's a wchar) 2- Where collisions occur assume a literal string is char[]. 3- Decide the type based on the contents. I have no problem with (0), (1) is simply another way to express the same thing which is the programmer stating "this literal is an x[]". (2) might have hidden bug consequences in the (unlikely?) event there are 2 functions of the same name taking different char types, doing different tasks. (3) is like (2) except it's additionally optimisation, after all UTF-8, 16, and 32 can all represent all the information, they just do it with differing byte usage. Regan |
Copyright © 1999-2021 by the D Language Foundation