alias function this - limitations
div0
div0 at users.sourceforge.net
Thu Jun 24 11:01:47 PDT 2010
On 24/06/2010 13:52, Simen kjaeraas wrote:
> struct Ref( T ) {
> T* payload;
> @property ref T getThis( ) {
> return *payload;
> }
> @property ref T getThis( ref T value ) {
> payload = &value;
> return *payload;
> }
> alias getThis this;
> }
>
> void bar( ) {
> Ref!int f;
> int n;
> f = n;
> int b = f;
> }
>
> This code fails on the line 'int b = f;'. Is it supposed to?
>
I think so.
'alias this' is used to forward stuff that appears to the right of a dot
onto the named member.
In c++ to get what you are doing to work, you'd add a customer cast
operator:
http://www.digitalmars.com/d/2.0/operatoroverloading.html#Cast
but I'm not sure how the cast operator overloading works in D, I don't
know if it will try to implicitly cast and call your operator.
--
My enormous talent is exceeded only by my outrageous laziness.
http://www.ssTk.co.uk
More information about the Digitalmars-d-learn
mailing list