Casting Structs

Philippe Sigaud via Digitalmars-d digitalmars-d at puremagic.com
Sun Jun 1 11:33:04 PDT 2014


At the very least, it's contradicted by the website:

http://dlang.org/expression#CastExpression

"Casting a value v to a struct S, when value is not a struct of the
same type, is equivalent to: S(v)"

In your case, you have no 'this' in Decimal to accept a Decimal with
other arguments. This should not work.
Timon provides a nice example:

struct A{
    int a,b;
}
struct B{
    long x;
}

void main(){
    auto a=A();
    auto b=cast(B)a;
}

Here, cast(B)a should be transformed into B(a). AFAICT, this should
not compile, but it does.


More information about the Digitalmars-d mailing list