reference to an interface

kris foo at bar.com
Tue Apr 11 12:39:45 PDT 2006


Jari-Matti Mäkelä wrote:
> kris wrote:
> 
>>Frank Benoit wrote:
>>
>>>An interface is something like a promise. A class implementing an
>>>interface promises to have all these methods. Your class C2 is
>>>overriding the method from C1 that's all. Your two "help" methods are
>>>not two different one, they are the same.
>>>
>>>C2 promises twice to implement a methods "void help();", inherants the
>>>one from C1 and overrides it.
>>
>>That's a really good analogy/description ...
> 
> 
> Indeed. But when will it promise to sort things too (== when will it
> really treat instances of an interface as objects) ;)
> 
> #interface comparable {
> #        int opCmp(Object o);
> #}
> #
> #class item : comparable {
> #        int opCmp(Object o) { return 1; }
> #}
> #
> #void main() {
> #        comparable[] c; // compiler/lang spec "problem" here
> #        c ~= new item;
> #        c ~= new item;
> #        c ~= new item;
> #
> #        c.sort; // segfaults here
> #}
> 
> 


That's an implementation issue. D had a long and sordid history in this 
regard ~ I used to be one of the primary antagonists, but gave up long ago



More information about the Digitalmars-d-learn mailing list