I'll describe the problem. I have a class with API, which invokes a large hierarchy of class member functions to do some logic. Now, I updated the logic so each function in the hierarchy requires an extra argument (the API did not change).
A thought - instead of adding an extra parameter to each method, I can add a 'scrathpad' member to the class, I.e a variable which is only used for temporary calculations, and is only 'valid' inside the time scope of API call and is 'garbage' once the call is finished.
Example:
void A::api()
{
scratch_pad = get_some_value_once();
foo1();
}
void A::foo1() { ...; foo2(); }
void A::foo2() { ...; foo3(); }
...
void A::fooN() /* Called 100000000 times */
{
...;
// Do something with scratch_pad.
// I would realy like to avoid adding 'scratch_pad' parameter to all the foos().
}
Is this a valid approach?
Will it still be valid if my API is declared as const?