Possible to overload assignment of struct field ??

Ali Çehreli acehreli at yahoo.com
Tue Aug 24 05:34:08 UTC 2021


On 8/23/21 10:25 PM, james.p.leblanc wrote:

So, you need a "property". Easy... :)

1) Rename the member e.g. as a_.

2) Write setter and getter functions named 'a'.

struct Foo{
   int a_;

   int a() const {
     return a_;
   }

   void a(int value) {
     a_ = value;
   }
}

void main(){
   auto x = Foo(1);
   x.a = 100;
   assert(x.a == 100);
}

Ali


More information about the Digitalmars-d-learn mailing list