2
這是怎麼回事?enable_if和構造函數
我認爲這應該工作時使用啓用,如果???
幫助??
不應該排除第二個構造函數嗎?
#include <iostream>
#include <boost/type_traits.hpp>
#include <boost/utility/enable_if.hpp>
template<class T>
class integral_holder{
public:
integral_holder(T value_, typename boost::enable_if_c< boost::is_integral<T>::value>::type* ignore = 0) : value(value_){
std::cout << "Integral" << std::endl;
}
integral_holder(T value_, typename boost::enable_if_c< boost::is_floating_point<T>::value>::type* ignore = 0) : value(floor(value_)){
std::cout << "Floating point" << std::endl;
}
private:
T value;
};
int main(int argc, const char * argv[])
{
integral_holder<int> a(22);
return 0;
}
你能舉個例子嗎? – 2012-07-07 14:15:21
模板 類integral_holder { 公共: 模板 integral_holder(U VALUE_,類型名的boost :: enable_if_c <提高:: is_integral ::值> ::類型*忽略= 0); template integral_holder(U value_,typename boost :: enable_if_c :: value> :: type * ignore = 0); 私有: T值; }; –
2012-07-07 14:21:14
@BlairDavidson,這是正確的。 – 2012-07-07 21:35:21