i get this error in Visual studio 2008:
Error 1 error C2664: ‘BaseUtil::Type::CDouble::CDouble(const BaseUtil::Type::CDouble &)’ : cannot convert parameter 1 from ‘boost::icl::no_type’ to ‘const BaseUtil::Type::CDouble &’
Here my class interface:
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;
};
The code that trigger the compile error:
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
}
I don’t understand the error and don’t know how to solve it.
It work wells with basic type(int, double, ..)
Anyone can help ?
Here’s the length fonction from boost 1.52 header files:
Found in the file: boost\icl\type_traits\difference_type_of.hpp
So I’m assuming that the boost header files defaut implementation for a type that support difference numerical operator is no_type.
What must be done, is to provide, at compile time, a definition of a difference type that match one of your contructor. Ie, the contructor copy for instance is your case.
Although, your type seems like a wapper on a numeric value, maybe boost header files doesn’t get it. Please test this snippet in one of your header files, out of proprietary namespaces.
If it doesn’t works as is, the trick is to tell to boost that your type has a diffence type (a CDouble) so that copy constructor does works.