Hello all,

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
    {
        ...
    }

However, this runs into a problem: I can't use "static" to internally store a class instance.

I worked out a cheaty way to get around this which goes like this:

    ref MyClass myProperty() @property
    {
        struct MyCheat
        {
            MyClass whatIReallyWant = new MyClass;
        }

        static MyCheat cheat;
        // ... do other stuff ...
        return cheat.whatIReallyWant;
    }

... but I'm wondering if anyone has any alternative suggestions (or warnings or caveats about the cheaty method).

Thanks & best wishes,

    -- Joe

Reply via email to