toString ugliness

Jarrett Billingsley jarrett.billingsley at gmail.com
Sat Dec 6 08:45:10 PST 2008


On Sat, Dec 6, 2008 at 11:21 AM, Jerry <jlquinn at optonline.net> wrote:
> toString() doesn't work inside a class member function.
>
> import std.string;
> class A {
>  void f() {
>    string s = toString(5);
>  }
> }
>
> This errors with junk.d(19): function object.Object.toString () does not match parameter types (int)
>
> This is a nuisance and a wart (though not a bug per-se).
>
> If the language really can't handle distinguishing this.toString() from toString(int), then std.string.toString really should have a different name.
>
> It can be solved somewhat by documenting clearly that to!(string)(int)
> be used instead, which seems silly to me.  I'm irritated by the 3 extra chars required to type a to!(type) template.
>
> .toString() works around the problem, but why should it be needed?  This is unfortunate.
>
> Does this bother anyone else?  If not, I'll return to my lurking cave :-)
>

It's annoying but it's not enough to make me want to change anything.  ;)



More information about the Digitalmars-d mailing list