structs, classes, interfaces - Part III, Solution
Reiner Pope
some at address.com
Sat Sep 1 17:07:22 PDT 2007
Jari-Matti Mäkelä wrote:
> Daniel Keep wrote:
>
>>
>> Jari-Matti Mäkelä wrote:
>>> ...
>>>
>>> interface IA { void foo(); }
>>> interface IB { int bar(); }
>>>
>>> struct A : IA { void foo() { writefln("hello"); }
>>> struct B : IB { int bar() { return 42; } }
>>>
>>> struct C : IA, IB {
>>> mixin A;
>>> mixin B;
>>> }
>> I believe this will be possible using:
>>
>> struct C : IA, IB {
>> private A a;
>> private B b;
>> alias a this;
>> alias b this;
>> }
>>
>
> I don't doubt it isn't possible, but it needs to be implemented first too :)
> One problem I see in the new aliasing syntax is that it introduces two
> unnecessary symbols C.a and C.b as an side effect. (but it could allow you
> to choose between a.foo and b.foo if foo happens to conflict, though)
I wonder if we can extend the alias this syntax to get rid of the
unnecessary symbols. Since, conceptually, aliasing just "binds" the
second name to the first, giving the first variable a new name, why
don't we just allow variables to be named "this". The code above becomes
struct C : IA, IB {
A this;
B this;
}
To me it's quite consistent with "alias b this".
-- Reiner
More information about the Digitalmars-d
mailing list