matching overloaded functions (std.string.toString)

Carlos Santander csantander619 at
Sat Feb 3 13:34:20 PST 2007

Rick Mann escribió:
> I'm not sure I understand the matching rules for overloaded functions. I have a type:
> typedef int OSStatus;
> and I want to call
> OSStatus err;
> toString(err);
> but I get these errors:
> function std.string.toString called with argument types:
>         (OSStatus)
> matches both:
>         std.string.toString(char)
> and:
>         std.string.toString(real)
> It more readily matches toString(int). I realize the spec says that if a match is ambiguous, then it's an error, but it sure would be nice if this worked.
> So, I tried defining my own toString(OSStatus):
> char[]
> toString(OSStatus inVal)
> {
> 	return std.string.toString(cast (int) inVal);
> }
> But I get the same error.
> Can someone tell me why? Surely an exact match would be acceptable. Thanks!

Instead of "import std.string" try "static import std.string", so you can only 
call std.string.toString by its FQN. Or import it privately and use your 
toString from another module (which doesn't import std.string)

Carlos Santander Bernal

More information about the Digitalmars-d-learn mailing list