equivariant functions
    Steven Schveighoffer 
    schveiguy at yahoo.com
       
    Tue Oct 14 18:44:22 PDT 2008
    
    
  
"Denis Koroskin" wrote
> Now that I thought about it a little more (please, see and comment my post 
> about typeof(this) nearby), I agree that the issues are related.
>
> However, the best solution could be a combination of both.
>
> For example, I agree that interface IClonable should be as follows:
>
> interface IClonable { typeof(this) clone() const; }
No.  IClonable should be:
IClonable clone() const;
or if you prefer:
Object clone() const;
It can't be anything else, because IClonable cannot define how many levels 
deep it goes.
For example, if I have:
class A : IClonable
{
  typeof(this) clone() const { return new A();}
}
class B : A
{
}
B b = new B;
B x = b.clone();
Oops, b.clone() really only returns A, so this should fail.  The real 
signature in A should be:
class A : IClonable
{
   A clone() const { return new A(); }
}
IClonable is a perfect candidate for covariant functions, which is already 
defined.
-Steve 
    
    
More information about the Digitalmars-d
mailing list