Why there are no 'physical' object variables (only references)?

Reiner Pope reiner.pope at REMOVE.THIS.gmail.com
Wed Sep 13 02:09:20 PDT 2006


Steve Horne wrote:
> On Wed, 13 Sep 2006 06:33:19 +1000, Reiner Pope
> <reiner.pope at REMOVE.THIS.gmail.com> wrote:
> 
>> interface Foo
> <SNIP>
>> struct Bar : Foo
> <SNIP>
>> void calc(Foo f) { ... }
>>
>> How can calc know the type of every struct it is passed unless a 
>> separate version of calc is generated for every type (in which case it 
>> is just a template)?
> 
> Compiler generated proxy object, containing a vtable and a pointer to
> the struct.
What's the difference between this and a class, then?

> Mind you, it's very dodgy, to say the least. I have argued for struct
> inheritance, but this is not the kind of inheritance I want.
I don't understand what you do want, then. Interface inheritance 
requires class-like vtables, and once you've got that you've basically 
got a class, anyway. *Implementation* inheritance can be done using mixins.

Of course, in D, implementation inheritance via mixins is a bit limited 
-- you can only mix in templates, not structs. I see no technical reason 
why you couldn't mix in any class, function, or struct that you have the 
source code for. This basically means implicitly templatizing whatever 
you want to mix in.

Cheers,

Reiner



More information about the Digitalmars-d mailing list