开发者

Template function in define

开发者 https://www.devze.com 2023-01-01 12:40 出处:网络
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);

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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号