Reputation: 51
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 ?
Upvotes: 1
Views: 140
Reputation: 51
Thank you for your answer but i used this instead:
namespace std
{
template <>
class numeric_limits<BaseUtil::Type::CDouble> : public numeric_limits<double>
{
};
}
Upvotes: 1
Reputation: 26
Here's the length fonction from boost 1.52 header files:
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);
}
Found in the file: boost\icl\type_traits\difference_type_of.hpp
template <class Type>
struct get_difference_type<Type, false, false>
{
typedef no_type type;
};
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.
#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 );
};
} }
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.
Upvotes: 1