Why can't we derive struct's? (Hansel & Gretel)

luckoverthere luckoverthere at gmail.cm
Fri Dec 28 00:50:11 UTC 2018


On Friday, 28 December 2018 at 00:36:15 UTC, H. S. Teoh wrote:
> On Fri, Dec 28, 2018 at 12:25:14AM +0000, luckoverthere via 
> Digitalmars-d wrote:
>> On Thursday, 27 December 2018 at 20:15:04 UTC, Jonathan M 
>> Davis wrote:
>> > As it is, I think that having even a single alias this 
>> > should be done with caution and relatively rarely. And if we 
>> > had the ability to have multiple alias this-es on a type, I 
>> > would think that it should be used extremely rarely. But the 
>> > very fact that it existed could have some nasty 
>> > repercussions (especially for generic code). I don't know 
>> > that that means that we shouldn't have the feature, but it 
>> > definitley concerns me.
> [...]
>> Arguably, in a sense, we already have multiple alias this's. 
>> It just has to be done through 1 alias this per struct.
>> 
>> 
>> struct A {
>>   int a;
>> };
>> 
>> struct B {
>>     A a_;
>>     int b;
>>     alias a_ this;
>> }
>> 
>> struct C {
>>     B b_;
>>     int c;
>>     alias b_ this;
>> }
> [...]
>
> That's not multiple alias this, that's just a chain of alias 
> this's. A linear class inheritance hierarchy is not equivalent 
> to multiple inheritance.
>
>
> T

Indeed, keen observation!

struct C {
     A a_;
     B b_;
     int c;

     alias a_ this;
     alias b_ this;
}

Sure you can arrange the structure differently and don't need to 
have one object contain another. Can have the same type for alias 
this'd. But in the context of the discussion of the comment I was 
replying to. It is possible to replicate the same feature of 
multiple alias this, as you can implicitly convert to multiple 
types.


More information about the Digitalmars-d mailing list