【发布时间】:2018-10-10 22:53:38
【问题描述】:
我试过了:
template<typename P, typename = std::enable_if_t<std::is_arithmetic<P>::value>>
void f(std::vector<P>* a) {
// body for arithmetic P
}
template<typename P, typename = std::enable_if_t<std::is_class<P>::value>>
void f(std::vector<P>* a) {
// body for class P
}
本以为条件互斥会重载f,结果发现编译不通过:“函数模板已定义”。
如果我想让f(std::vector<P>*) 的函数体依赖于P 是否算术,该怎么办?
【问题讨论】:
-
查看
std::enable_if用法的常见错误。
标签: c++ templates c++14 overloading