Only const or immutable class thread local variables are allowed
Joseph Rushton Wakeling
joseph.wakeling at webdrake.net
Sun Dec 8 10:00:03 PST 2013
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
More information about the Digitalmars-d-learn
mailing list