首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >模板参数的C++模板参数

模板参数的C++模板参数
EN

Stack Overflow用户
提问于 2014-07-04 10:15:27
回答 1查看 47关注 0票数 0

看看这段代码:

代码语言:javascript
复制
template<class T, class Compare>
void foo(const std::set<T, Compare> & bar)
{
    // here I need the comparative function BUT with another type
    // like this:
    if (Compare<float>()(...))
}

就像这样,但不管用:

代码语言:javascript
复制
template<class T, class Compare>
void foo(const std::set<T, Compare<T>> & bar)
...

有可能吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-04 10:17:53

您需要一个模板参数:

代码语言:javascript
复制
template<class T, template<class> class Compare>

现在,Compare模板参数本身就是一个模板。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24571997

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档