A renewed call for interface methods with bodies

Robert Fraser fraserofthenight at gmail.com
Thu Jan 24 18:11:40 PST 2008


Burton Radons wrote:
> BCS Wrote:
> 
>> Burton Radons wrote:
>> [...]
>>
>>
>> something just occurred to me:
>>
>> The only actions that a function body in an interfaces could do to 
>> "this" is function calls that would have to be virtual (or how could it 
>> ever do anything) however the code generated for a interface method 
>> needs to know the type of the object to be able to make the calls 
>> correctly. The only reasonable way I can see to let interface functions 
>> have bodies would be to in effect use a mixin.
>>
>> Can anyone think of a better solution?
> 
> There aren't any problems in compiling interface methods with bodies - it's exactly the same as a class with abstract methods. This part of the compiler should behave the same between interfaces and classes, it's just prevented from doing so by the compiler's semantic checker.
> 
> This has never been a compiler issue (IIRC there were DMD versions which accidentally allowed interface methods with bodies), it's purely a language design mistake by Walter. I've been doing a LOT of COM interfacing the last half year and it's been painful every step of the way just because of this one little bit of missing polish.

There actually is a language issue: What if a class implements two 
interfaces that both declare the same method, but the class doesn't? 
Which one is called?

BTW, I really need to stop checking this every 10 minutes...



More information about the Digitalmars-d mailing list