c++ - Boost::icl::no_type 错误

标签 c++ boost

我在 Visual Studio 2008 中遇到此错误: 错误 1 ​​error C2664: 'BaseUtil::Type::CDouble::CDouble(const BaseUtil::Type::CDouble &)' : 无法将参数 1 从 'boost::icl::no_type' 转换为 'const BaseUtil::Type::C双&'

这是我的类界面:

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);
}

在文件中找到:boost\icl\type_traits\difference_type_of.hpp

template <class Type>
struct get_difference_type<Type, false, false>
{
    typedef no_type type;
};

所以我假设支持差异数字运算符的类型的 boost 头文件默认实现是 no_type

必须做的是在编译时提供与您的构造函数相匹配的差异类型的定义。例如,构造函数拷贝就是您的情况。

虽然,您的类型看起来像是一个数值的包装器,但也许 boost 头文件没有得到它。请在专有 namespace 之外的一个头文件中测试此代码段。

#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 你的类型有一个差异类型(一个 CDouble),这样复制构造函数就可以工作。

关于c++ - Boost::icl::no_type 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14198919/

相关文章:

c++ - sqlite 错误 : compilation error C1017 SQLITE_ENABLE_COLUMN_METADATA

c++ - 在为请求选择服务的情况下,使用 Boost ICL 而不是 for_each 是否可能且合理?

c++ - 如何使用 BOOST_FOREACH 枚举 BOOST_ENUM?

c++ - Boost:如何处理时间相关的线程操作?

c++ - 使用 C++ 在 Arduino 上编写复杂的程序。如何正确使用对象或更好地使用普通 C?

c++ - libxml2 2.7.8/libxml++ 2.35 和 DTD 验证的变化

c++ - GLSL 中的索引是什么?

c++ - 如何在屏幕上的随机位置绘制一个字符 - C++

C++、Mac OS X、Xcode 8 : Compile Boost : Set deployment target to OS X 10. 11

Boost Jam 与 Jam