Why there are no 'physical' object variables (only references)?
Reiner Pope
reiner.pope at REMOVE.THIS.gmail.com
Tue Sep 12 13:33:19 PDT 2006
BCS wrote:
> Lionello Lunesu wrote:
>> BCS wrote:
>>
>>> Sean Kelly wrote:
>>>
>>>> Kristian wrote:
>>>>
>>>>>
>>>>> Hmm, what if structures could have interfaces and
>>>>> constructors/destructors... and what the heck, inheritance too?
>>>>> Hehheh, this way we would have 'physical classes' for local use and
>>>>> 'reference classes' for global use.
>>>>
>>>>
>>>>
>>>> It will never happen :-) Though ctor support would be nice, at the
>>>> very least. That would simplify initialization and eliminate the
>>>> need for the static opCall trick.
>>>>
>>>>
>>>> Sean
>>>
>>>
>>> There is no technical reason struct (or anything that can produce a
>>> delegate) can't do interfaces. Inheritance on the other hand... I
>>> hope that never happens.
>>
>>
>> Wouldn't it add a hidden __vtbl to your struct and thereby increasing
>> its size?
>>
>> L.
> No, because the type of a struct is always known, the required value for
> the interface's function table can be found at compile time and all that
> is needed is to attach it to a reference to the struct.
I don't understand you. How would it work?
Suppose you had this code:
interface Foo
{
int foo();
}
struct Bar : Foo
{
int foo() { ... }
...
}
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)?
Cheers,
Reiner
More information about the Digitalmars-d
mailing list