August 13, 2016 Re: mixin bug? | ||||
---|---|---|---|---|
| ||||
Posted in reply to sldkf | On Friday, 12 August 2016 at 23:48:54 UTC, sldkf wrote:
> On Friday, 12 August 2016 at 23:14:23 UTC, Engine Machine wrote:
>> On Friday, 12 August 2016 at 15:35:50 UTC, sldkf wrote:
>>> On Friday, 12 August 2016 at 02:09:21 UTC, Engine Machine wrote:
>>>> On Thursday, 11 August 2016 at 21:25:20 UTC, sldkf wrote:
>>>>> On Thursday, 11 August 2016 at 20:27:01 UTC, Engine Machine
>>
>> This is not the solution to the original problem.
>>
>> template X(T)
>> {
>> int _len = 0;
>> int Length() { return _len; }
>> int length(this T)() { return (cast(T)this).Length(); }
>> }
>>
>> template Y(T)
>> {
>> mixin X!T;
>> int Length() { return 3; }
>> }
>>
>>
>> Then calling length returns 0, while calling Length returns 3. But we obviously want length to "follow" Length, yet it doesn't due to D resolving length in X before it is mixed in Y!T.
>
> No "length" returns 3.
>
> https://ideone.com/T8HjZl
>
> Really, it's there, in front of your eyes.
You're right. My mistake. Thanks!
Do I have to do this with every function call? Seems a bit tedious to have to add this T to every function and add this. to every call.
|
Copyright © 1999-2021 by the D Language Foundation