C++ Boost::icl::无类型错误
我在Visual studio 2008中遇到以下错误: 错误1错误C2664:'BaseUtil::Type::CDouble::CDouble(const BaseUtil::Type::CDouble&'):无法将参数1从'boost::icl::no_Type'转换为'const BaseUtil::Type::CDouble&' 这里是我的类接口:C++ Boost::icl::无类型错误,c++,boost,C++,Boost,我在Visual studio 2008中遇到以下错误: 错误1错误C2664:'BaseUtil::Type::CDouble::CDouble(const BaseUtil::Type::CDouble&'):无法将参数1从'boost::icl::no_Type'转换为'const BaseUtil::Type::CDouble&' 这里是我的类接口: class CDouble { public: CDouble(); CDouble(const CDouble& _o
class CDouble
{
public:
CDouble();
CDouble(const CDouble& _obj);
CDouble(const double& _val);
bool operator==(const CDouble& _obj) const;
bool operator==(const double& _obj) const;
bool operator!=(const CDouble& _obj) const;
bool operator<=(const CDouble& _obj) const;
bool operator>=(const CDouble& _obj) const;
bool operator< (const CDouble& _obj) const;
bool operator> (const CDouble& _obj) const;
CDouble& operator= (const CDouble& _obj);
CDouble& operator+=(const CDouble& _obj);
CDouble& operator-=(const CDouble& _obj);
const CDouble operator+(const CDouble& _obj) const;
const CDouble operator-(const CDouble& _obj) const;
const double operator/(const CDouble& _obj) const;
CDouble& operator= (double _value);
CDouble& operator+=(double _value);
CDouble& operator-=(double _value);
CDouble& operator*=(double _value);
CDouble& operator/=(double _value);
const CDouble operator+(double _value) const;
const CDouble operator-(double _value) const;
const CDouble operator*(double _value) const;
const CDouble operator/(double _value) const;
operator double() const {return m_value;}
private:
CDouble& operator*=(const CDouble& _obj);
const CDouble operator*(const CDouble& _obj) const;
CDouble& operator/=(const CDouble& _obj);
double m_value;
};
class-CDouble
{
公众:
CDouble();
CDouble(const CDouble和_obj);
CDouble(常数双值);
布尔运算符==(常数CDouble和_obj)常数;
布尔运算符==(常数双和_obj)常数;
布尔运算符!=(常数CDouble和_obj)常数;
布尔运算符=(常数CDouble&_obj)常数;
布尔运算符<(常数CDouble和_obj)常数;
布尔运算符>(常数CDouble和_obj)常数;
CDouble和运算符=(常数CDouble和对象);
CDouble和运算符+=(常量CDouble和对象);
CDouble和运算符-=(常数CDouble和对象);
常数CDouble运算符+(常数CDouble&_obj)常数;
常量CDouble运算符-(常量CDouble&_obj)常量;
常量双运算符/(常量CDouble和_obj)常量;
CDouble&运算符=(双值);
CDouble和运算符+=(双值);
CDouble和运算符-=(双值);
CDouble和运算符*=(双值);
CDouble和运算符/=(双值);
常数CDouble运算符+(双值)常数;
常量CDouble运算符-(双值)常量;
常数CDouble运算符*(双值)常数;
常数CDouble运算符/(双值)常数;
运算符double()常量{返回m_值;}
私人:
CDouble和运算符*=(常数CDouble和对象);
常数CDouble运算符*(常数CDouble和_obj)常数;
CDouble和operator/=(const CDouble和_obj);
双m_值;
};
触发编译错误的代码:
template <class BoundType>
class Interval
{
public:
BoundType Length() const
{
return boost::icl::length(
boost::icl::construct<boost::icl::interval<BoundType>::type>(m_LowerBound, m_UpperBound, m_IntervalType())
);
}
private:
BoundType m_LowerBound, m_UpperBound;
typedef boost::icl::interval_bounds (*IntervalType)();
IntervalType m_IntervalType;
}
int main()
{
Interval<CDouble> typeDouble(-1.0, 1.0);
typeDouble.Length(); //<-- COMPILE ERROR
}
模板
课间休息
{
公众:
BoundType Length()常量
{
返回boost::icl::length(
boost::icl::construct(m_LowerBound,m_UpperBound,m_IntervalType())
);
}
私人:
BoundType m_LowerBound,m_Upper Bound;
typedef boost::icl::interval_界限(*IntervalType)();
区间型m_区间型;
}
int main()
{
区间型双精度(-1.0,1.0);
typeDouble.Length();//以下是boost 1.52头文件的长度函数:
template<class Type>
inline typename boost::enable_if<is_continuous_interval<Type>,
typename difference_type_of<interval_traits<Type> >::type>::type
length(const Type& object)
{
typedef typename difference_type_of<interval_traits<Type> >::type DiffT;
return icl::is_empty(object) ? identity_element<DiffT>::value()
: upper(object) - lower(object);
}
模板
内联类型名boost::enable_if::type
长度(常数类型和对象)
{
typedef typename difference_type_of::type DiffT;
返回icl::是否为空(对象)?标识元素::值()
:上部(对象)-下部(对象);
}
在文件中找到:boost\icl\type\u traits\difference\u type\u of.hpp
template <class Type>
struct get_difference_type<Type, false, false>
{
typedef no_type type;
};
模板
结构获取差异类型
{
typedef无_型;
};
因此,我假设支持差分数值运算符的类型的boost头文件defaut实现是no_type
必须做的是,在编译时提供一个与您的构造函数之一匹配的差异类型的定义。例如,构造函数副本就是您的例子
尽管您的类型看起来像是一个数值上的wapper,但可能boost头文件没有得到它。请在您的头文件中测试此代码段,使用专有名称空间
#include <boost_1_52_0\boost\icl\type_traits\is_numeric.hpp>
namespace boost{ namespace icl
{
template <>
struct is_numeric<CDouble>
{
typedef is_numeric type;
BOOST_STATIC_CONSTANT(bool, value = true );
};
} }
#包括
命名空间boost{namespace icl
{
模板
结构是数字的
{
typedef是数字类型;
BOOST_静态_常数(bool,值=真);
};
} }
如果它不能按原样工作,诀窍是告诉boost您的类型有一个差异类型(CDouble),这样复制构造函数就可以工作了。谢谢您的回答,但我使用了这个:
namespace std
{
template <>
class numeric_limits<BaseUtil::Type::CDouble> : public numeric_limits<double>
{
};
}
名称空间std
{
模板
类别数字限制:公共数字限制
{
};
}