使用ostream和print功能进行打印,具有内部功能

时间:2018-06-21 13:48:12

标签: c++11

我想打印多项式。我不知道这是否是语法问题,或者我只是不了解某些内容

class polynom : public func {
  public:
  polynom(const int order, int* ptr_array); 
  polynom(const polynom& polynom_); 
  void printcoefs(ostream&)  const ;
  friend polynom operator+(polynom const &, polynom const &) ;
  friend polynom operator-(polynom const &, polynom const &);
  friend polynom operator*(polynom const &, polynom const &);
  polynom operator=(polynom const & poly) { //assignment operator
      int* ptr = new int[poly.n_ + 1];
      for (int i = 0; i < poly.n_ + 1; i++)
          ptr[i] = poly.coefs_[i];
      return polynom(poly.n_, ptr);
      }
  polynom Derivative();
  polynom Integral();
  int funcout(const int& x) const;
  friend ostream & operator<<(ostream& out, const polynom& polynom_);
  ~polynom();
  void Print(ostream& out) const;

protected:
  int n_; //order of the polynom
  int* coefs_; //coefficients 
};

这是我为pritning函数编写的

  void polynom::Print(ostream &out) const {
     printcoefs(cout);
     cout << endl;
     cout << "Derivative: ";
     polynom der=this->Derivative;  <-error here
     der.printcoefs(cout);
     cout << endl;
     polynom inte =this->Integral;
     cout << "Integral: ";
     inte.printcoefs(cout);
     cout << endl;
  }
ostream & operator<<(ostream & out, const polynom & polynom_)
 {
    polynom_.Print(out);
     return out;
 }

它给了我 错误C3867'polynom :: Derivative':非标准语法;如果我这样写的话,使用'&'创建一个指向member的指针。 错误C2276'*':如果我尝试使用“ this”作为指针,则对绑定成员函数表达式进行非法操作。 任何帮助将不胜感激

0 个答案:

没有答案