toString ugliness

Jerry jlquinn at optonline.net
Sat Dec 6 09:11:32 PST 2008


Jarrett Billingsley Wrote:

> 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.

As I'm thinking about this, why does this actually fail?  The parameter doesn't match the prototype for this.toString(), so why not match against the global function?

Is this due to the behavior that override solves?  Would marking Object.toString() as override fix the problem?




More information about the Digitalmars-d mailing list