alias this and opDot()
Salih Dincer
salihdb at hotmail.com
Wed Sep 28 03:45:59 UTC 2022
Ok, opDot() is deprecated in version 2.082. However, if we
simulate this situation with a function (opdot in our example),
we get unexpected results.
```d
struct Point { int x, y; }
struct S
{
Point point;
alias opdot this;
auto opdot()
{ // opDot() is deprecated in v2.082
//this.point = Point(100, 100);/* <-- also if you only use:
s == Point(100, 101)
point.x = 100;
point.y = 100;
point.x++;//*/
return &point;
}
}
void main()
{
S s;
s.x++; // as if this line doesn't exist!
s.y++;
//s.x++; // <-- also if you use: s == Point(102, 100)
assert(s.point == Point(101, 101));
}
```
SDB at 79
More information about the Digitalmars-d
mailing list