Abstract Classes vs Interfaces

Robert Jacques sandford at jhu.edu
Wed Jul 7 11:44:16 PDT 2010


On Wed, 07 Jul 2010 14:38:09 -0400, Robert Jacques <sandford at jhu.edu>  
wrote:
> On Wed, 07 Jul 2010 13:36:16 -0400, Jonathan M Davis  
> <jmdavisprog at gmail.com> wrote:
>
>>> Consider the following:
>>>
>>> interface A { final void foobar() { writeln("A"); } }
>>> interface B { final void foobar() { writeln("B"); } }
>>>
>>> class C : A, B {}
>>>
>>> void main(string[] args) {
>>>
>>>      C c = new C;
>>>      c.foobar;
>>>
>>> }
>>>
>>> What does foobar print?
>>> (This has been filed as bug 4435:
>>> http://d.puremagic.com/issues/show_bug.cgi?id=4435)
>>
>> I believe that per TDPL, you would have to call these with eithe  
>> c.A.foobar() or
>> c.B.foobar() but that c.foobar() is not allowed. If it is allowed at  
>> present,
>> it's definitely a bug. However, it's a bug in the implementation rather  
>> than the
>> language spec.
>>
>> - Jonathan M Davis
>
> TDPL Page 215-216, mentions function hijacking of a final function by  
> the implementor, which is listed as an error and detected correctly.  
> Function hijacking of static functions by the implementor is not handled  
> correctly. It also specifically mentions that c.A.foobar() is not the  
> correct, nor ideal syntax. Indeed, it doesn't currently compile.

Since I forgot to mention it, c.foobar is the correct syntax.


More information about the Digitalmars-d mailing list