On 12/08/2013 10:00 AM, Joseph Rushton Wakeling wrote:

> I have a challenge, which is this: I'd like to have a public property
> which will return a reference to an internally stored class instance.
>
>      ref MyClass myProperty() @property
>      {
>          ...
>      }

First, the usual question: Since class varibles are already references, do you really need to return ref?

In any case, I think class static this is the solution:

class MyClass
{
    static MyClass whatIReallyWant;

    static this()
    {
        whatIReallyWant = new MyClass;
    }

    /* ref */ MyClass myProperty() @property
    {
        return whatIReallyWant;
    }
}

void main()
{
    auto m = new MyClass;
    auto s = m.myProperty;
}

Ali

Reply via email to