In the code below the cm variable is allocated on the stack and the addConstraints is the prototype of a method :
ConstraintManager cm(5);
void addConstraints(ConstraintManager& cm);
When I call addConstraints I want to reinitialize the cm variable inside the body of the function. That is call its constructor such as doing like cm(3)so that it is reinitialized to contain 3 instead of 5. However I am not able to do that and the only thing I can do is:
ConstraintManager temp(3);
cm = temp;
Is there a way to achieve this in a more concise way ? Thanks.
If there’s no direct means to change that member in the public interface of the class, that means, in my book, that you’re not supposed to change it.
If you must, what you already have is the way to do it, only less verbose: