There are several ways of ensuring that width
is always "in sync" with the left and right:
- Making
tagRECTEx
immutable, and setting thewidth
in the constructor, or - Adding setter functions for all your variables, and updating
width
every timeleft
orright
is changed, or - Replacing
width
variable with thewidth()
member function, like this:
int width() {
return right-left;
}
I prefer this last method, because it is usually more economical, and because it greatly reduces the probability of introducing bugs during maintenance.