Reference to implementation of interface.

Christian Aistleitner xy7p3vxz at gmx.net
Sat Jan 20 02:08:59 PST 2007


Hello,

On Fri, 19 Jan 2007 22:41:55 +0100, Pragma  
<ericanderton at yahoo.removeme.com> wrote:

> Christian Aistleitner wrote:
>> Hello,
>>  I am in need of a way to reference the class implementing an interface  
>> from within the interface's definition.
>
> Offhand, I'd say the best way to do that is with a templated base-class  
> or interface.  For example:
>
> interface Bar(T){
>      static T baz; // in the class below, 'baz' will by of type 'Foo'
> }
>
> class Foo: Bar!(Foo){
> }

although I see that your code allows to model the problem, its actually  
artificial and rather cumbersome to pass the implementing class as a  
parameter, wherever I'd need such an operator.
And the knowledge that the parameter Foo has to match the class' name is  
implicit by the design and cannot be checked by the compiler.

Kind regards,
Christian


More information about the Digitalmars-d-learn mailing list