开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜