I have a class named ResourceBin.
int getResource(Resources resource) const;
void setResource(Resources resource, int amount);
int addResource(Resources resource, int amount);
unsigned int getMax(Resources resource) const;
void setMax(Resources resource, unsigned int amount);
bool simulateAddResource(Resources resource, int amount) const;
bool maxOn = true;
ResourceBin operator+(const ResourceBin& bin);
unsigned int maxamount;
unsigned int getIndex(Resources resource) const;
typedef ResourceBin ResourceList;
The short answer is: practically no. You have to make
maxOn a private class member, and provide its own getter and setter method.
The reason for the "practically" qualifier is that it's possible to build a house of cards which will result in a statement of the form:
execute a class method.
maxOn wouldn't be an ordinary
bool, but a custom class, with an
operator= and an
operator bool(), making it act like a
bool value, but the
operator= would update the flag, and, using a number of approaches, execute a method in its parent class to validate the required constraint.
It's possible, and it's quite a bit of work. But don't do that. It's ugly. Just replace
maxOn with a getter and a setter.