On Tuesday, 20 July 2021 at 09:24:07 UTC, Mark Lagodych wrote:
Is there a way to make myvar local to each instance of `X`
without making it a variable of `X`? Just curious.
Sorry if I missed something obvious but is there a specific
reason why it isn't just a class member variable?
```d
On Tuesday, 20 July 2021 at 15:59:30 UTC, Dukc wrote:
On Tuesday, 20 July 2021 at 09:24:07 UTC, Mark Lagodych wrote:
Is there a way to make myvar local to each instance of `X`
without making it a variable of `X`? Just curious.
Yes.
```d
import std.stdio;
class X {
int x(int param) {
On Tuesday, 20 July 2021 at 09:24:07 UTC, Mark Lagodych wrote:
Is there a way to make myvar local to each instance of `X`
without making it a variable of `X`? Just curious.
Yes.
```d
import std.stdio;
class X {
int x(int param) {
static int[typeof(this)] myvar;
if (param
On Tuesday, 20 July 2021 at 09:24:07 UTC, Mark Lagodych wrote:
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
On Tuesday, 20 July 2021 at 09:24:07 UTC, Mark Lagodych wrote:
```d
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;
}
```
Ow, sorry, I forgot to say. It prints:
```
1234
1234
17
17
```
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;