|
我总是搞不懂运算符重载的问题比如:
#include <iostream>
using namespace std;
class Complex
{public:
friend ostream &operator <<(ostream &,Complex &);
friend istream &operator >>(istream &,Complex &);
private:
double real;
double imag;
};
ostream &operator <<(ostream &output,Complex &c)
{output<<"("<<c.real<<"+"<<c.imag<<"i)";
return output;}
istream &operator >>(istream &input,Complex &c)
{cout<<"input real part and imaginary part of complex number:";
input>>c.real>>c.imag;
return input;}
int main()
{Complex c1,c2;
cin>>c1>>c2; /*这句连着输入两个值是怎么输入的,我知道"cin>>"是函数重载可以理解,但后面又出现个>>c2我就不理解了难道(cin>>c1>>)也是函数的重载?哪位有空,请详细解释一下。谢谢*/
cout<<c1<<endl;
cout<<c2<<endl;
return 0;
}
我输入5 6
它回输出(5+6I)但我搞不懂它的return output和return input分别返回的是什么,返回给谁。 |
|