小编Jos*_*yan的帖子

重载'operator ++'必须是一元或二元运算符(有3个参数)

我有一个头文件和一个.cpp文件.我试图实现前缀和后缀运算符重载,但我在设置重载时不断收到此错误.

fraction.h

#ifndef FRACTION_H
#define FRACTION_H

#include <iostream>

using namespace std;

class Fraction 
{
   public:
      Fraction();
      Fraction(int, int);
      int getTop() {return m_top;}
      int getBottom() {return m_bottom;}
      void set(int t, int b) {m_top=t; m_bottom=b; reduce();
      }

   protected:
   private:
      void reduce();
      int gcf(int, int);

      int m_top;
      int m_bottom;
};

Fraction& operator ++ (Fraction);
Fraction operator++(Fraction, int);

#endif
Run Code Online (Sandbox Code Playgroud)

Main.cpp的

#include <iostream>

using namespace std;
#include "fraction.h"

int main {
   cout << "The fraction is" << f;
   cout << "The output of ++f is …
Run Code Online (Sandbox Code Playgroud)

c++ xcode operator-overloading pre-increment post-increment

6
推荐指数
1
解决办法
6157
查看次数