Template function in define
I have some template function and I want to call it using define in C++:
#define CONFI开发者_运维百科G(key, type, def) getValue<type>(key, def);
Of course, it won't work. Could I make something like this?
It works fine:
template<typename T>
T getValue( int, int ) { return T(); }
#define CONFIG(key, type, def) getValue<type>(key, def);
int main()
{
CONFIG(1, int, 2);
return 0;
}
精彩评论