I don't want to edit the common part of the source code repeatedly.
So I separate the other parts with different functions as below.
/* Origin */
void MyClass::threadFunc_A()
{
// many variables in this function
...
// do something A
...
}
void MyClass::threadFunc_B()
{
// many variables in this function
...
// do something B
...
}
/* I wish */
void MyClass::threadFunc(type)
{
// many variables
int a, b;
char c, d, e;
...
string x, y, z;
...
// case
if (type == A) do_something_A();
if (type == B) do_something_B();
...
if (type == Z) do_something_Z();
}
void do_something_A()
{
// using "many variables (a ~ z)" here
a = 10;
b = 20;
...
}
In the case of macro functions, I know that the code is built in when compiling, so that variables within the same range can be used.
However, if the do_something() function is lengthened, there is a limit to writing using the macro function.
Is there a way to write an inline function like 'I wish' in C++ 17 or higher? (Except for putting A as a member variable of the class or making it a structure and passing it)