I have to define new instances of a type Inst with some arguments … using the syntax NEWNSTANCE where NEWINSTANCE is a macro. It is clear that with the follow code the compiler will complain about a redefinition of ex but I have to follow this syntax.
// error redefinition ok very clear
#define NEWINSTANCE Inst ex(…)
int main() {
NEWINSTANCE;
NEWINSTANCE;
NEWINSTANCE;
}
I can't write NEWINSTANCE(name) to get inst name(…). Now I want to create “random” names for new instances. I don't care about the specific names.
Is possible to write something like ex ## __LINE__ (…) to have something like Inst ex1(…), Inst ex2(…) and multiple of them?
I am thinking of something like this but it is not working as expected.
#define NEWINSTANCE Inst ex ## __LINE__ (…)
int main() {
NEWINSTANCE; // Inst ex6(…)
NEWINSTANCE; // Inst ex7(…)
NEWINSTANCE; // Inst ex8(…)
}