C++ 为模板构造函数使用SFINAE时出现问题

C++ 为模板构造函数使用SFINAE时出现问题,c++,templates,sfinae,c++03,c++98,C++,Templates,Sfinae,C++03,C++98,以下两项之间的区别是什么: template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> explicit Approx(const T& value) {} 您的C++03版本不起作用,因为给定参数,它无法推导t。构造函数常用的C++03机制是一个额外的默认参数 template<typename

以下两项之间的区别是什么:

template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
explicit Approx(const T& value) {}

您的C++03版本不起作用,因为给定参数,它无法推导t。构造函数常用的C++03机制是一个额外的默认参数

template<typename T>
explicit Approx(const T& value, typename std::enable_if<std::is_constructible<double, T>::value>::type* dummy = 0) {}
模板
显式近似值(常量T&value,typename std::enable_if::type*dummy=0){}
T
在这种形式下是可以推断的,如果
T
满足
enable\u if
指定的期望值,那么额外的参数最终将是
void*

class Volatility {
    double underlying_;
public:
    explicit Volatility(double u) : underlying_(u) {}
    explicit operator double() const { return underlying_; }
};

Approx(Volatility(1.)); // error
template<typename T>
explicit Approx(const T& value, typename std::enable_if<std::is_constructible<double, T>::value>::type* dummy = 0) {}