Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 运算符+的重载不明确;_C++ - Fatal编程技术网

C++ 运算符+的重载不明确;

C++ 运算符+的重载不明确;,c++,C++,Boost数学库中存在多项式类:。我想通过添加新函数来扩展此类的功能,并使用继承,如下所示: #ifndef POLY_HPP #define POLY_HPP #include <boost/math/tools/polynomial.hpp> template <class T> class Poly : public boost::math::tools::polynomial<T>{ public: Poly(const T* data,

Boost数学库中存在多项式类:。我想通过添加新函数来扩展此类的功能,并使用继承,如下所示:

#ifndef POLY_HPP
#define POLY_HPP

#include <boost/math/tools/polynomial.hpp>

template <class T>
class Poly : public boost::math::tools::polynomial<T>{
public:

    Poly(const T* data, unsigned order) : boost::math::tools::polynomial<T>(data, order){

    }
};

#endif 
#如果聚乙烯水电站
#定义POLY_水电站
#包括
模板
类Poly:public boost::math::tools::polynomic{
公众:
多边形(常数T*数据,无符号顺序):boost::math::tools::Polyman(数据,顺序){
}
};
#恩迪夫
现在我声明该类的两个对象,并希望添加它们:

    int a[3] = {2, 1, 3};
    Poly<int> poly(a, 2);
    int b[2] = {3, 1};
    Poly<int> poly2(b, 1);
    std::cout << (poly + poly2) << std::endl;
inta[3]={2,1,3};
Poly(a,2);
int b[2]={3,1};
Poly-poly2(b,1);

就我所知,这是不可能的,你需要像

template <class T>
Poly<T> operator + (const Poly<T>& a, const Poly<T>& b) {
    return Poly<T>(static_cast< boost::math::tools::polynomial<T> >(a) +
                   static_cast< boost::math::tools::polynomial<T> >(b));
}
模板
多边形运算符+(常数多边形和a、常数多边形和b){
返回多边形(静态_cast(a)+
静态_cast(b));
}
要消除调用的歧义(在类中需要从
boost::math::tools::polymone
Poly
的适当转换构造函数…

多项式是否有虚拟析构函数?我不这么认为,因此,从中获得公共遗产是非常危险的
boost::math::tools::polynomial<T> boost::math::tools::operator+(const boost::math::tools::polynomial<T>&, const boost::math::tools::polynomial<T>&)
template <class T>
Poly<T> operator + (const Poly<T>& a, const Poly<T>& b) {
    return Poly<T>(static_cast< boost::math::tools::polynomial<T> >(a) +
                   static_cast< boost::math::tools::polynomial<T> >(b));
}