Will alias this work for classes too?
Jascha Wetzel
"[firstname]" at mainia.de
Thu Sep 13 10:00:52 PDT 2007
Sean Kelly wrote:
> Janice Caron wrote:
>> On 9/13/07, Jascha Wetzel <"[firstname]"@mainia.de> wrote:
>>> that would be a different syntax for regular MI and is therefore
>>> probably not going to happen.
>>
>> "alias this" is already slated in in the Walter Andrei document.
>> Walter apparently /wants/ "alias this", and it looks like it will work
>> as I outlined - at least for structs. Classes? I don't know. That's
>> why I asked.
>
> If I had to guess, I'd say "alias this" will basically perform a mix-in
> of the data. So I don't see any reason why it couldn't work for classes.
mixin merely copies declarations at compile-time. "alias b this" in the
sense of the version from Walter's and Andrei's slides, would have to
use the reference to the aggregated object to access it's members.
a couple of issues come to mind:
- while a method that has been mixed in can be overridden in a subclass,
a method that has been imported via alias-this can't (unless alias-this
would change the vtable of the importing class, which would lead to real
MI).
- consider this:
class A { void foo(int); }
class B { void foo(int); }
class C : A { override void foo(int); }
class D : B
{
C c;
alias C this;
}
what is D.foo?
- the diamond problem of MI also arises
- accessing a member (even if it's of primitive type) can result in an
access violation although the reference used by the caller is non-null -
the aggregated object might be null.
sure, these issues can be overcome, but it appears similarly complex as
real MI to me.
More information about the Digitalmars-d
mailing list