A bug with matching overloaded functions?
Jonathan M Davis
jmdavisProg at gmx.com
Wed Dec 1 10:58:25 PST 2010
On Wednesday, December 01, 2010 08:42:23 flyinghearts wrote:
> void check(string s) {}
> void check(wstring s) {}
> void check(dstring s) {}
>
> void main()
> {
> check("test");
> //check("test"c);
> }
>
>
> D:\Desktop\d\zb.d(7): Error: function zb.check called with argument types:
> ((string))
> matches both:
> zb.check(string s)
> and:
> zb.check(immutable(dchar)[] s)
>
>
>
>
>
> The type of "test" is string, isn't it?
Not exactly. A string literal implictly casts to all 3 string types. You can add
a suffix to force it to be a wstring or dstring (I don't think that there's a suffix
for a normal string though), or you can cast it to the exact one you want, or
you can assign it to a variable first. If you use auto, I believe that it will
default to string rather than wstring or dstring, but string literals implicitly
cast to all 3, so the compiler considers your code to be ambiguous.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list