小编Ama*_*mai的帖子

如何解决运算符>>重载错误(不匹配'运算符>>')

我已经查看了有关此问题的其他主题,并试图查看是否可以找到我的错误,但我无法找到如何解决我的错误.

我的错误:

no match for ‘operator>>’ (operand types are ‘std::istream {aka std::basic_istream<char>}’ and ‘Polynomial()’)
cin >> p3;
Run Code Online (Sandbox Code Playgroud)

主要:

// includes, namespace, etc...

int main()
{
    Polynomial p3();

    // Prompts user and assigns degrees and coefficients
    cout << "Enter the degree followed by the coefficients: ";
    cin >> p3;

    // other coding
 }
Run Code Online (Sandbox Code Playgroud)

运算符>>的头文件定义:

class Polynomial 
{
      private:
          double *coefs;
          int degree;
      public:
          // constructors, setters/getters, functions
          friend std::istream &operator >>(std::istream &in, Polynomial &poly);
};
Run Code Online (Sandbox Code Playgroud)

实施文件:

Polynomial::Polynomial() // default constructor
{ …
Run Code Online (Sandbox Code Playgroud)

c++ overloading operator-keyword

3
推荐指数
1
解决办法
67
查看次数

标签 统计

c++ ×1

operator-keyword ×1

overloading ×1