Gerando funções com macros em C ++
Eu tenho a macro a seguir que se destina a gerar funções no escopo atual ou namespace:
#define MAKE_FUNC(FNAME) \
template <typename T> \
T ##FNAME## (const T& t) \
{\
return t; \
}
MAKE_FUNC(foo)
MAKE_FUNC(boo)
int main()
{
foo(1);
boo(2);
}
O seguinte é a mensagem de erro ao compilar o código acima:
prog.cpp:8:1: error: pasting "Tfoo" and "(" does not give a valid preprocessing token
prog.cpp:9:1: error: pasting "Tboo" and "(" does not give a valid preprocessing token
prog.cpp:8: error: ISO C++ forbids declaration of ‘Tfoo’ with no type
prog.cpp:9: error: ISO C++ forbids declaration of ‘Tboo’ with no type
prog.cpp: In function ‘int main()’:
prog.cpp:13: error: ‘foo’ was not declared in this scope
prog.cpp:14: error: ‘boo’ was not declared in this scope
Parece que a concatenação falhou, existe alguma maneira em torno desse problema?