Boost::icl::no_type error
Boost::icl::no_type error
我在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& _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;
};
触发编译错误的代码:
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
}
我不明白这个错误,也不知道如何解决。
它可以很好地处理基本类型(int, double,…)
有人能帮忙吗?
下面是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);
}
在文件中找到:boosticltype_traitsdifference_type_of.hpp
template <class Type>
struct get_difference_type<Type, false, false>
{
typedef no_type type;
};
所以我假设boost头文件默认实现支持差异数值运算符的类型是no_type。
必须做的是在编译时提供一个与你的一个构造函数匹配的差异类型的定义。例如,构造函数副本就是你的例子。
虽然,你的类型看起来像一个数字值的waper,也许boost头文件没有得到它。请在您的头文件中测试此代码片段,不要使用专有的命名空间。
#include <boost_1_52_0boosticltype_traitsis_numeric.hpp>
namespace boost{ namespace icl
{
template <>
struct is_numeric<CDouble>
{
typedef is_numeric type;
BOOST_STATIC_CONSTANT(bool, value = true );
};
} }
如果它不能正常工作,诀窍是告诉boost你的类型有一个不同的类型(CDouble),这样复制构造函数就能正常工作。
谢谢你的回答,但我用这个代替:
namespace std
{
template <>
class numeric_limits<BaseUtil::Type::CDouble> : public numeric_limits<double>
{
};
}
相关文章:
- 由于"error C4430: missing type specifier - int assumed. Note: C++ does not support default-int",我现在无法编
- 为什么<error-type>从模板类切换时会出现 ?
- 如何修复" State Error (active) E0513 a value of type "const wchar_t *" cannot be assigned to an entity o
- 修复第三方代码:"error: ‘enable_if’ in namespace ‘std’ does not name a template type"
- 仅当链接函数 C++ 时,才会发生"Expression must have class type error"
- 返回的向量定义为 "std::vector<<error-type>, std::allocator<<error-type>>>
- 类定义内部"error: 'a' does not name a type"
- 为什么我有"Expected type specifier error"?
- 不知道为什么我会得到"error: does not name a type "
- 在 Solaris 机器上使用 SUN C++ 进行编译时"Error: incomplete type "无符号字符 [] " "
- 内存集调用位置的"error: expected constructor, destructor, or type conversion before '(' token"
- 非整数常量声明 - dev-error:在此范围内未声明"type"
- 在编辑器中"Error: type name is not allowed"消息,但不在编译期间
- 使用 "this" 关键字时的"Error: expression must have a pointer type"
- 使用 Boost.Log "error: target { simple_event_log.mc. } has no type" 构建 Boost
- 在C++,我收到一条消息"error: 'void*' is not a pointer-to-object type"
- 为什么我使用这些意大利面模板会"error: type name is not allowed"?
- 同时在另一个类中创建类的对象,该类仅具有参数化的 Ctor "error: x is not a type"
- 为什么我的代码会抛出"does not name a type error"?
- 获取"does not name a type error",但我正在命名一个类型