alias this doesn't work for properties.

Maxim Fomin maxim at maxim-fomin.ru
Thu Aug 1 19:21:20 PDT 2013


On Thursday, 1 August 2013 at 21:56:46 UTC, John Colvin wrote:
>
> You are asking for an "int" to be be implicitly convertable to 
> an "A", which isn't possible.

http://dpaste.dzfl.pl/c3cce6e2

import std.stdio;


class A
{
     double x;
     @property double X() { writeln("From A.Get"); return x; }
     @property double X(double v) { writeln("From A.Set"); x = v; 
return x; }
     alias X this;
	this(double val) { this.x = val; }
}

class B
{
	A a;
     A Y() { writeln("From B.Get"); return a; }
     A Y(A v ...) { writeln("From B.Set"); a =  v; return a; }

	this() { a = new A(0); }
}


void main()
{
	B b = new B();
	writeln(b.Y);
	b.Y = 3;
	writeln(b.Y);

	readln();
}


More information about the Digitalmars-d mailing list