[Issue 8001] New: Alias this takes ownership of explicit cast
Namespace
rswhite4 at googlemail.com
Wed May 2 11:31:42 PDT 2012
This works fine:
[code]
import std.stdio;
class A {
int val;
alias val this;
T opCast(T : Object)() {
return to!(T)(this);
}
}
class B : A {
}
T to(T : Object, U : Object)(const U obj) {
return *(cast(T*) &obj);
}
void main () {
A a = new B();
a.val = 42;
writefln("a.val: %d", a.val);
B* b = cast(B*) &a;
writefln("*b.val: %d", b.val);
B b1 = to!(B)(a);
writefln("b1.val: %d", b1.val);
B b2 = cast(B) a;
writefln("b2.val: %d", b2.val);
}
[/code]
More information about the Digitalmars-d-bugs
mailing list