下面是复数类complex的定义,其中作为友元函数重载的运算符“--”的功能是将参数对象的实部减1,然后返回对该对象的引用:请补充完整。 class complex { private: int real; int

admin2009-02-15  23

问题 下面是复数类complex的定义,其中作为友元函数重载的运算符“--”的功能是将参数对象的实部减1,然后返回对该对象的引用:请补充完整。
   class complex
   {
    private:
     int real;
     int imag;
   public:
     complex(int r=0,int i=0):real(r),imag(i){}
     void show()
     {
      cout<<real<<(imag<0?"-":"+")<<imag<<’i’;
    }
     【  】;
   };
   complex& operator--(complex &C)
   {
     c.real--;
     return c;
   }

选项

答案friend complex& operator--(complex&)

解析 本题考核运算符重载的定义。程序要填入的是运算符函数operator--在类 complex中的声明,运算符“--”是作为友元函数重载的。根据题目给出的条件,易得到答案。
转载请注明原文地址:https://kaotiyun.com/show/Zzjp777K
0

最新回复(0)