I am currently writing a class that performs a rather complex computation that should be triggered by one function call.
The steps of using the class would be:
- Construction including the initialization of the basic parameters
- Initialization with some more case specific settings
- The actual computation
- Now, the user of the class can fetch the outputs that are stored as class variables.
Step 2 is separated from step 1 so you can perform multiple computations with the same parameters by simply changing the case specific ones instead of creating a new object.
The large computation shall now be separated into several auxiliary functions. My approach for this is using private void
functions that only handle class variables, e.g.,
class MyComputation {
public:
MyComputation(/* some basic parameters */);
void initSpecificCase(/* some case specific parameters */);
void doTheActualComputation();
Results getResults();
private:
void computeThisAndThat();
void computeSomeInterimResults();
// Inputs, outputs, interim results
};
where doTheActualComputation
calls computeThisAndThat
and computeSomeInterimResults
.
Is this use of private functions good practice? Or should I rather put all the auxiliary stuff into an anonymous namespace? This would result in passing lots of arguments to the functions in the anonymous namespace, also some complex container stuff.
Please note that this question is not about passing arguments but rather about the use of void
private member functions with the assumption that the mentioned interim results make sense as class variables as they actually describe the state of the class object.