Voldemort type: getPoint()
Salih Dincer
salihdb at hotmail.com
Tue Apr 26 18:20:50 UTC 2022
As long as the Voldemort type lives on, does int x, y legally
live on?
```d
auto getPoint()
{
int x, y; // major issue
enum type = "2D";
struct Point(string Id)
{
static int _x = 1024;
static int _y = 768;
string toString() {
import std.format;
return format("Limit: %dx%d px.",
_x, _y);
}
void set(int a, int b) { x = a; y = b; }
uint area() { return x * y; }
auto get() { return this; }
}
auto px = Point!type();
return px.get;
}
```
For test:
```d
auto p1 = getPoint();
p1.set(2, 21);
p1.area.writeln(" MP, ", p1);
typeof(p1).stringof
.writefln!"%s @%s"(&p1);
p1.set(10, 100);
p1.area.writeln(" MP, ", p1);
auto p2 = getPoint();
p2.area.writeln(" MP, ", p2);
p2.set(3, 21);
typeof(p2).stringof
.writefln!"%s @%s"(&p2);
p1.area.writeln(" MP, ", p1);
p2.area.writeln(" MP, ", p2);
```
Outputs:
>42 MP, Limit: 1024x768 px.
Point!"2D" @7FFD328DB770
1000 MP, Limit: 1024x768 px.
0 MP, Limit: 1024x768 px.
Point!"2D" @7FFD328DB788
1000 MP, Limit: 1024x768 px.
63 MP, Limit: 1024x768 px.
SDB at 79
More information about the Digitalmars-d
mailing list