const(Object)ref is here!

Simen kjaeraas simen.kjaras at gmail.com
Tue Dec 21 11:01:26 PST 2010


On Tue, 21 Dec 2010 19:46:11 +0100, Andrej Mitrovic  
<andrej.mitrovich at gmail.com> wrote:

> Hmm.. if we get uniform function call syntax for all types, perhaps
> this code might even work some day:
>
> import std.stdio;
> import std.conv;
>
> string toString(A)(A a)
> {
>     return to!string(a);
> }
>
> class A
> {
>     string name;
>     this(string name)
>     {
>         this.name = name;
>     }
>     string writeTo()
>     {
>         return name;
>     }
> }
>
> void main()
> {
>     auto foo = new A("I'm foo! ");
>     writeln(foo.toString);  // using uniform function call syntax
> }
>
> Right now this code will compile but it will use Object's toString
> instead of the one we defined above.

It would still use Object's toString, as member functions would be
tested for first.

-- 
Simen


More information about the Digitalmars-d mailing list