toString not working... (a bug in D?)
Daniel Giddings
dgiddings at bigworldtech.com
Tue Jan 16 15:04:12 PST 2007
I've found use of format better in many cases as with tuple's the
compiler can get confused as to which toString variant to use (giving a
link error because its trying to compile a call in to toString(bool) on
a char[]), and it happily avoids any naming conflicts with the toString
of your class.
class Test {
void method(int number) {
char[] text="Some text " ~ format(number);
}
}
Marcin Kuszczak wrote:
> Orgoton wrote:
>
>> Ok, now I did
>>
>> import std.string;
>> ushort number=1092;
>> char[] text="Some text " ~ toString(number);
>>
>> and the compiler claimed that the number of arguments of
>> Object.object.toString() did not match... So, I did
>>
>> char[] text="Some text " ~ std.string.toString(number);
>>
>> and it worked fine. Is this a compiler bug? I did not import object (as it
>> is implicitly done). Or have I some weird compiler configuration?
>
> Probably you did:
> char[] text="Some text " ~ toString(number);
>
> in class method, so compiler thought you want to refer to Object's
> toString() method.
>
> You should escape current scope of class with '.' (dot).
> class Test {
> void method(int number) {
> char[] text="Some text " ~ .toString(number);
> }
> }
>
> Above code should work.
>
More information about the Digitalmars-d
mailing list