Public variables inside interfaces

Peter Alexander peter.alexander.au at gmail.com
Sat Apr 30 06:01:42 PDT 2011


On 30/04/11 1:22 PM, Mariusz Gliwiński wrote:
> I like the possibility of abandoning () in function calls in D, so we
> can firstly make attribute public and then if implementation changes,
> smoothly change it into function:
> <snip>
>
> Although, if I'd like to make interface Sizeable, it's impossible to
> treat attribute and method equally:
> <snip>
>
> Is it possible to make it work?
>
> Best regards,
> Mariusz Gliwiński

No, interface functions require entries in the v-table, so the 
implementing class needs to have a function.

You could certainly get around it using mixins and metaprogramming, but 
there's no need for that level of complexity when all you need to do is 
implement a function that returns a member variable.


More information about the Digitalmars-d mailing list