我有一些模板函数,我想在 C++ 中使用 define 调用它:
#define CONFIG(key, type, def) getValue<type>(key, def);
当然不行。我可以做这样的东西吗?
最佳答案
它工作正常:
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;
}
关于c++ - 定义中的模板函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2924673/