2013-01-07 36 views
1

我在Visual Studio 2008中出現此錯誤: 錯誤1錯誤C2664:'BaseUtil :: Type :: CDouble :: CDouble(const BaseUtil :: Type :: CDouble &)':無法從 '提高:: ICL :: no_type' 轉換參數1到 '常量BaseUtil ::類型:: CDouble &'Boost :: icl :: no_type錯誤

這裏我的類接口:

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,雙,..)

任何人都可以幫助嗎?

回答

1

下面是從提升1.52頭文件長度fonction:

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

在文件中找到:升壓\ ICL \ type_traits \ difference_type_of.hpp

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

所以我假設升壓頭文件默認實現一個支持差分數值運算符的類型是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); 
    }; 
} } 

如果它不工作的原樣,關鍵是要告訴,以提高你的類型有diffence類型(CDouble),以便拷貝構造函數的作品。

+0

謝謝你,它的工作。 – Myrky

1

謝謝您的回答,但我用這個來代替:

namespace std 
{ 
    template <> 
    class numeric_limits<BaseUtil::Type::CDouble> : public numeric_limits<double> 
    { 
    }; 
}