This is a clear sign that you should separate these individual blocks into separate functions.
MyStruct3 DoSth3(params) { double temporary_var; // Functional step 1.1 // Functional step 1.2 return ... } MyStruct4 DoSth4(params) { double temporary_var; // Functional step 2.1 // Functional step 2.2 intermediate_var4 = ... } void my_algorithm(const MyStruct1 &iparam1, MyStruct2 &oparam2) { // First block MyStruct3 intermediate_var3 = DoSth3(params); // Second block MyStruct4 intermediate_var4 = DoSth4(params); int temporary_var; oparam2 = ... }
You might be worried that DoSth3 and DoSth4 are publicly available, as they should be private in the context of my_algorithm . In this case, you can solve it as follows:
class my_algorithm { private: static MyStruct3 DoSth3(params); static MyStruct4 DoSth4(params); public: static void Perform(const MyStruct1 &iparam1, MyStruct2 &oparam2); };
source share