I have a struct that describes how the system should be initialised. I then have a method that returns a reference to said struct so that the user of the final system can change certain options after initialisation. I wish to detect when a value is changed and tell the component parts of the system to check for options they depend on to see if they've been changed and update themselves accordingly.
I believe such a thing is possible by overloading an operator or something similar. I don't really mind about overhead and what the detection & updating code looks like, I just want the syntax for changing an option to look clean, and for the user to not have to call a updateOptions()
function after changes or anything.
Firstly, is this even possible? Secondly, if it is, how would I go about it?
I will assume your struct is named
Fun
Solution 1: Add getter, setter and notify
I would write a getter and a setter for each properties of the said struct. It would look like this:
Of course, the reference can be a pointer and of course, you will have to separate the struct to a header and cpp file.
Solution 2: write a get and set for the struct Fun
The advantage of this solution is that it might be the fastest, and of course the cleanest one.