A
A
Can this be done (and how) in C++ in the following pseudo-code form:
DEFINE_I_TO_1
{
int i=1;
}
int increaseby1()
{
DEFINE_I_TO_1
return i+1;
}
int increaseby2()
{
DEFINE_I_TO_1
return i+2;
}
In other words - I would like to keep all the scopes, definitions etc and
just to insert a reusable piece of code - much like copy-pasting a block of
template code.
Of course, I could put it in a function, but I would like to know also if
there is a way to do it this way because in certain uses this would make
sense - like loops where timing is critical putting inline code would
obviously be faster way than calling a function.
I know C++ has macros and templates but from what I've seen they are not
intended to be used like this. Or am I wrong?
Is this possible and what is the easiest way to achieve this if possible?
DEFINE_I_TO_1
{
int i=1;
}
int increaseby1()
{
DEFINE_I_TO_1
return i+1;
}
int increaseby2()
{
DEFINE_I_TO_1
return i+2;
}
In other words - I would like to keep all the scopes, definitions etc and
just to insert a reusable piece of code - much like copy-pasting a block of
template code.
Of course, I could put it in a function, but I would like to know also if
there is a way to do it this way because in certain uses this would make
sense - like loops where timing is critical putting inline code would
obviously be faster way than calling a function.
I know C++ has macros and templates but from what I've seen they are not
intended to be used like this. Or am I wrong?
Is this possible and what is the easiest way to achieve this if possible?