I'm wanting to know how, if there is a way, to "build" variables through a loop. I'm not interested in using an array. This is an example of what I'm trying to do:
1 2 3 4 5
#define concat(a, b) a ## b
...
int a1, a2, a3;
for (int i = 1; i <= 3; ++i)
concat(a, i) = i;
My macro is broken. You can see how it tries to create variable "ai" instead of "a" with the value of "i". Is there a way to get this concat macro working so that it is effectively replaced with a1, a2, then a3 through the loop?
As you may already know, the preprocessor runs at compile time (before the compiler) and your macro is dependent on runtime symbols. You need a way to determine the range of your loop at compile time for a start.
Make a base class with a virtual method, inherit from it for each of your implementations, construct the appropriate object in main, and just call the method. Polymorphism: the C++ way to do that.