Thread overview
toString() not working within class member function?
Feb 02, 2005
Nick Sabalausky
Feb 02, 2005
Nick Sabalausky
Feb 02, 2005
Nick Sabalausky
Feb 02, 2005
zwang
Feb 02, 2005
Nick Sabalausky
Feb 03, 2005
Thomas Kuehne
Feb 03, 2005
Regan Heath
Feb 03, 2005
Thomas Kuehne
Mar 16, 2005
Walter
Mar 17, 2005
Thomas Kuehne
February 02, 2005
The following code generates an error:

-----
import std.string;
class MyClass
{
    void Display()
    {
        toString(1); // This line generates an error
    }
}
void main(char[][] args)
{
}
------

The compiler error is:
test.d(7): function object.Object.toString () does not match argument types
(int)
test.d(7): Error: expected 0 arguments, not 1

The following variations compile fine:
-----
import std.string;
class MyClass
{
    void Display()
    {
        std.string.toString(1); // Works fine
    }
}
void main(char[][] args)
{
}
-----
void main(char[][] args)
{
    toString(1); // Works fine
}
-----


February 02, 2005
This is with DMD 0.110.  I haven't tried 0.112 yet.

"Nick Sabalausky" <z@a.a> wrote in message news:ctpknf$21se$1@digitaldaemon.com...
> The following code generates an error:
>
> -----
> import std.string;
> class MyClass
> {
>    void Display()
>    {
>        toString(1); // This line generates an error
>    }
> }
> void main(char[][] args)
> {
> }
> ------
>
> The compiler error is:
> test.d(7): function object.Object.toString () does not match argument
> types (int)
> test.d(7): Error: expected 0 arguments, not 1
>
> The following variations compile fine:
> -----
> import std.string;
> class MyClass
> {
>    void Display()
>    {
>        std.string.toString(1); // Works fine
>    }
> }
> void main(char[][] args)
> {
> }
> -----
> void main(char[][] args)
> {
>    toString(1); // Works fine
> }
> -----
>
> 


February 02, 2005
I just tried DMD 0.112 and got the same results.

"Nick Sabalausky" <z@a.a> wrote in message news:ctpkqk$21ud$1@digitaldaemon.com...
> This is with DMD 0.110.  I haven't tried 0.112 yet.
>
> "Nick Sabalausky" <z@a.a> wrote in message news:ctpknf$21se$1@digitaldaemon.com...
>> The following code generates an error:
>>
>> -----
>> import std.string;
>> class MyClass
>> {
>>    void Display()
>>    {
>>        toString(1); // This line generates an error
>>    }
>> }
>> void main(char[][] args)
>> {
>> }
>> ------
>>
>> The compiler error is:
>> test.d(7): function object.Object.toString () does not match argument
>> types (int)
>> test.d(7): Error: expected 0 arguments, not 1
>>
>> The following variations compile fine:
>> -----
>> import std.string;
>> class MyClass
>> {
>>    void Display()
>>    {
>>        std.string.toString(1); // Works fine
>>    }
>> }
>> void main(char[][] args)
>> {
>> }
>> -----
>> void main(char[][] args)
>> {
>>    toString(1); // Works fine
>> }
>> -----
>>
>>
>
> 


February 02, 2005
I don't think this is a bug, because MyClass derives from Object and
inherits the "char[] toString()" method which takes no argument.
You have to explicitly write std.string.toString here.


Nick Sabalausky wrote:
> The following code generates an error:
> 
> -----
> import std.string;
> class MyClass
> {
>     void Display()
>     {
>         toString(1); // This line generates an error
>     }
> }
> void main(char[][] args)
> {
> }
> ------
> 
> The compiler error is:
> test.d(7): function object.Object.toString () does not match argument types (int)
> test.d(7): Error: expected 0 arguments, not 1
> 
> The following variations compile fine:
> -----
> import std.string;
> class MyClass
> {
>     void Display()
>     {
>         std.string.toString(1); // Works fine
>     }
> }
> void main(char[][] args)
> {
> }
> -----
> void main(char[][] args)
> {
>     toString(1); // Works fine
> }
> -----
> 
> 
February 02, 2005
Ahh, I see. Now that you mention that, it's occurred to me that the module scope operator works too:

class MyClass
{
    void Display()
    {
       .toString(1); // That little dot does wonders ;)
    }
}

"zwang" <nehzgnaw@gmail.com> wrote in message news:ctpldp$22ba$1@digitaldaemon.com...
>I don't think this is a bug, because MyClass derives from Object and
> inherits the "char[] toString()" method which takes no argument. You have to explicitly write std.string.toString here.
>
>
> Nick Sabalausky wrote:
>> The following code generates an error:
>>
>> -----
>> import std.string;
>> class MyClass
>> {
>>     void Display()
>>     {
>>         toString(1); // This line generates an error
>>     }
>> }
>> void main(char[][] args)
>> {
>> }
>> ------
>>
>> The compiler error is:
>> test.d(7): function object.Object.toString () does not match argument
>> types (int)
>> test.d(7): Error: expected 0 arguments, not 1
>>
>> The following variations compile fine:
>> -----
>> import std.string;
>> class MyClass
>> {
>>     void Display()
>>     {
>>         std.string.toString(1); // Works fine
>>     }
>> }
>> void main(char[][] args)
>> {
>> }
>> -----
>> void main(char[][] args)
>> {
>>     toString(1); // Works fine
>> }
>> -----
>> 

February 03, 2005
Added to DStress as

http://dstress.kuehne.cn/run/overload_14.d
http://dstress.kuehne.cn/run/overload_15.d
http://dstress.kuehne.cn/run/overload_16.d

Note: this behavior might actually be the desired one, but I couldn't
find and documentation stating so.

Thomas

February 03, 2005
On Thu, 03 Feb 2005 05:01:47 +0100, Thomas Kuehne <thomas-dloop@kuehne.THISISSPAM.cn> wrote:
> Added to DStress as
>
> http://dstress.kuehne.cn/run/overload_14.d
> http://dstress.kuehne.cn/run/overload_15.d
> http://dstress.kuehne.cn/run/overload_16.d
>
> Note: this behavior might actually be the desired one, but I couldn't
> find and documentation stating so.

I believe it is, my reasoning:

The class inherits a toString method from it's parent "Object".

When you type "toString(1);" in a class method, name resolution begins by looking for a symbol called toString in the current scope, i.e. the class, then it looks in the parent class, finds toString() and gives an error because the number of parameters is all wrong.

The solution is to explicitly call the function you mean, or add an alias to the class eg.

class MyClass
{
    alias std.string.toString toString;
    void Display()
    {
        toString(1); // This line generates an error
    }
}

Regan
February 03, 2005
Regan Heath wrote:
| On Thu, 03 Feb 2005 05:01:47 +0100, Thomas Kuehne
| <thomas-dloop@kuehne.THISISSPAM.cn> wrote:
|
|> Added to DStress as
|>
|> http://dstress.kuehne.cn/run/overload_14.d
|> http://dstress.kuehne.cn/run/overload_15.d
|> http://dstress.kuehne.cn/run/overload_16.d
|>
|> Note: this behavior might actually be the desired one, but I
|> couldn't find and documentation stating so.
|
|
| I believe it is, my reasoning:
|
| The class inherits a toString method from it's parent "Object".
|
| When you type "toString(1);" in a class method, name resolution
| begins by  looking for a symbol called toString in the current scope,
| i.e. the class,  then it looks in the parent class, finds toString()
| and gives an error  because the number of parameters is all wrong.

The documentation is missing the statement about scoping-overloading
interaction.

The documentation only talks about overloading functions in base classes
and not about overloading functions that are part of the class' parent
scope(non-class member functions or class member functions of enclosing
classes).

Thomas
March 16, 2005
"Thomas Kuehne" <thomas-dloop@kuehne.THISISSPAM.cn> wrote in message news:ium8d2-vq3.ln1@lnews.kuehne.cn...
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Regan Heath wrote:
> | On Thu, 03 Feb 2005 05:01:47 +0100, Thomas Kuehne
> | <thomas-dloop@kuehne.THISISSPAM.cn> wrote:
> |
> |> Added to DStress as
> |>
> |> http://dstress.kuehne.cn/run/overload_14.d
> |> http://dstress.kuehne.cn/run/overload_15.d
> |> http://dstress.kuehne.cn/run/overload_16.d
> |>
> |> Note: this behavior might actually be the desired one, but I
> |> couldn't find and documentation stating so.
> |
> |
> | I believe it is, my reasoning:
> |
> | The class inherits a toString method from it's parent "Object".
> |
> | When you type "toString(1);" in a class method, name resolution
> | begins by  looking for a symbol called toString in the current scope,
> | i.e. the class,  then it looks in the parent class, finds toString()
> | and gives an error  because the number of parameters is all wrong.
>
> The documentation is missing the statement about scoping-overloading interaction.
>
> The documentation only talks about overloading functions in base classes and not about overloading functions that are part of the class' parent scope(non-class member functions or class member functions of enclosing classes).

It follows the rule that name resolution happens before overload resolution. Names outside the scope where the name was found do not participate in overload resolution.


March 17, 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Walter schrieb am Wed, 16 Mar 2005 13:39:13 -0800:
>
>> |> http://dstress.kuehne.cn/run/overload_14.d
>> |> http://dstress.kuehne.cn/run/overload_16.d
>
> It follows the rule that name resolution happens before overload resolution. Names outside the scope where the name was found do not participate in overload resolution.

Thanks - moved to http://dstress.kuehne.cn/nocompile/overload_14.d http://dstress.kuehne.cn/nocompile/overload_16.d

Thomas


-----BEGIN PGP SIGNATURE-----

iD8DBQFCOZuO3w+/yD4P9tIRAmJ+AKCtfo4hD8YAMtimM1Ggvy1om6TFagCgwPEv
lPSlLGI/f//XnaZhNDaqcXI=
=eJs/
-----END PGP SIGNATURE-----