So this is the old "paste happens before evaluation of macro arguments", so you get test__COUNTER__ instead of test0.
You need to do a nested macro:
#define expandedjoin(x,y) x##y
#define join(x, y) expandedjoin(x, y)
(The rest of your code gives lots of errors because you are passing a void
function to cout
, which isn't good)
Complete working code:
#include <iostream>
using namespace std;
#define expandedjoin(x,y) x##y
#define join(x, y) expandedjoin(x, y)
void join(test, __COUNTER__)()
{
cout << "\n 1";
}
void join(test, __COUNTER__)()
{
cout << "\n 2";
}
int main()
{
cout << "Hello world!" << endl;
test0();
test1();
return 0;
}