【发布时间】:2016-02-01 18:11:17
【问题描述】:
我想为一个类创建一个构造函数,使用任何整数类型,但要区分有符号和无符号。我不希望这成为类本身的模板。以下不起作用。 Visual Studio 只是说没有参数匹配。
class Thing{
public:
template<typename Integral>
Thing(
typename std::enable_if<
std::is_integral<Integral>::value &&
!std::is_same<Integral,bool>::value &&
std::is_signed<Integral>::value
,Integral
>::type num
){
//constructor using signed variable as input
}
template<typename Integral>
Thing(
typename std::enable_if<
std::is_integral<Integral>::value &&
!std::is_same<Integral,bool>::value &&
!std::is_signed<Integral>::value//notice this is different
,Integral
>::type num
){
//constructor using unsigned variable as input
}
};
【问题讨论】:
-
它不工作?它在做什么? :)
-
缺少
public关键字至少说明了我在尝试上面的代码时会遇到的第一个错误......
标签: c++ templates sfinae enable-if