toString ugliness

Ary Borenszweig ary at esperanto.org.ar
Sun Dec 7 04:10:30 PST 2008


Jerry escribió:
> 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 bothers me. Maybe it doesn't bother anyone else in this newsgroup 
because they already fell in that trap and they know the solution or the 
workarounds. For me, there shouldn't be a workaround, it should just 
work. If I, a human, can understand that toString(int) can't never, 
EVER, be confused with toString(), why can't the compiler see the same?



More information about the Digitalmars-d mailing list