alias this doesn't work for properties.

John Colvin john.loughran.colvin at gmail.com
Thu Aug 1 14:56:45 PDT 2013


On Thursday, 1 August 2013 at 20:42:08 UTC, JS wrote:
> http://dpaste.dzfl.pl/0c923861
>
> class A
> {
>     double x;
>     @property double X() { return x; }
>     @property double X(double v) { return x = v; }
>     alias X this;
> }
>
> class B
> {
>     A a;
>     @property A Y() { return a; }
>     @property A Y(A v) { return a = v; }
> }
>
>
> void main()
> {
> 	B b = new B();
> 	b.Y = 3;
> }
>
> error not a property of b.Y
>
>
>
> adding refs to the returns of the getters allows the code to 
> work but only getters are called(hence the need for refs).
>
> Please allow alias this to work with overloaded functions. 
> (specifically properties, b.Y = 3; is not b.Y() = 3 but b.Y(3);)

b.Y = 3 is rewritten as b.Y(3)

You are asking for an "int" to be be implicitly convertable to an 
"A", which isn't possible.


More information about the Digitalmars-d mailing list