I was looking for a workaround to multiple alias this (or opImplicitCast) the following trick doesn't work (why shouldn't it ?). The error message is quite obscure to me.

import std.stdio;

class A(Derived)
{
    alias cast(ref Derived)(this).x this;
}

class B : A!B
{
    float x;
}

class C : A!C
{
    int x;
}

void main()
{
    B b;
    b.x = 0.5;

    float f;
    f = b;
}


output :

source/app.d(5): Error: basic type expected, not cast
source/app.d(5): Error: no identifier for declarator int
source/app.d(5): Error: semicolon expected to close alias declaration
source/app.d(5): Error: Declaration expected, not 'cast'
Error: DMD compile run failed with exit code 1

Reply via email to