alias this doesn't work for properties.
Jesse Phillips
Jesse.K.Phillips+D at gmail.com
Thu Aug 1 18:46:26 PDT 2013
I'm going to provide a reduced case for the issue you are having.
struct Foo {
double x;
alias x this;
}
void main() {
Foo a;
a = 8; // Alias this assignment
assert(a.x == 8);
fun(7); // What you want
}
void fun(Foo a) {
}
You're claiming that since Foo is requested to "be" a double
calling fun(7) should just assign 7 to x.
What you're missing is that it is Foo which behaves like double,
however fun(7) there is no Foo involved, it doesn't exist. You're
actually requesting that a Foo is created, then to have an
assignment of 7 to x of the new temporary Foo.
This is not a bug, it is by design. Alias this is sugar of type
it is declared in not the type it is declared to.
More information about the Digitalmars-d
mailing list