gpt4 book ai didi

c++ - 定义中的模板函数

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:13:36 25 4
gpt4 key购买 nike

我有一些模板函数,我想在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com