Can static variables in methods be local for each object?
Mark Lagodych
lgd.mrk at gmail.com
Tue Jul 20 09:24:07 UTC 2021
Let's say I have this code:
```d
import std.stdio;
class X {
int x(int param) {
static int myvar = 1234;
if (param == 0) return myvar;
else { myvar = param; return myvar; }
}
}
void main()
{
X x1 = new X;
X x2 = new X;
x1.x(0).writeln;
x2.x(0).writeln;
x1.x(17).writeln;
x2.x(0).writeln;
}
```
Is there a way to make myvar local to each instance of `X`
without making it a variable of `X`? Just curious.
More information about the Digitalmars-d-learn
mailing list