Should have @property
Salih Dincer
salihdb at hotmail.com
Sun Jan 15 15:54:33 UTC 2023
In the code snippet below should have @property. Otherwise, we
get the result this:
> 40
> NP!(Foo!int)(opps!)
> NP!(Foo!int)(opps!)
```d
struct NP(V) {
private V payload;
this(V x)
{
payload = x;
}
alias opCall this;
@property: // <-- should be here
auto opCall() inout // ditto
{
return payload.value;
}
auto opCall(T)(T x)
{
return payload.value = x;
}
}
class Foo(T)
{
private T value;
NP!Foo wrapper;
this()
{
wrapper = NP!Foo(this);
}
override string toString()
{
return "opps!";
}
}
import std.stdio;
void main()
{
auto foo = new Foo!int;
foo.value = 40;
foo.value.writeln; // 40
foo.wrapper.writeln; // 40
foo.wrapper = 41;
foo.wrapper.writeln; // 41
}
```
SDB at 79
More information about the Digitalmars-d
mailing list