Possible to overload assignment of struct field ??

james.p.leblanc james.p.leblanc at gmail.com
Tue Aug 24 05:25:53 UTC 2021


Greetings,

With a struct, there are many overload possibilities available.

However, I haven't been able to find how to overload assignment
of **selected fields** of a struct.

For example, suppose:

     struct Foo{
       int a;
       int b;
       ...
     }

     void main(){
         auto x = Foo( 1, 2);  // so x now instantiates

         x.a = 100;             // suppose I wish to enforce that 
a<5??
     ...
     }


(I understand this is basically a field "setter" idea that is most
often associated with classes.  So, another way to state the 
quesion
might be:  "How can a field setter be done on a **already 
instantiated**
struct?)

Best Regards,
James




More information about the Digitalmars-d-learn mailing list