More Elegant Settable Methods?
jwatson-CO-edu
real.name at colorado.edu
Sat Jan 21 23:07:45 UTC 2023
Hi,
I am trying to create a struct with a settable method that has
access to the struct scope.
Is this the only way?
Is there a way to give access without explicitly passing `this`?
```d
import std.stdio;
struct TestStruct{
float /*------------------*/ a;
float /*------------------*/ b;
float function( TestStruct ) op;
float run(){
return op( this );
}
}
void main(){
TestStruct ts = TestStruct(
2,
3,
function( TestStruct s ){ return s.a + s.b; }
);
writeln( ts.run() );
}
```
More information about the Digitalmars-d-learn
mailing list