64,639
社区成员
发帖
与我相关
我的任务
分享
#include "iostream"
using namespace std;
class Complex
{
private:
int i;
int j;
public:
Complex(int i=0,int j=0) {
this->i=i;
this->j=j;
}
friend ostream &operator <<(ostream &o, Complex c) {
o <<c.i <<"+" <<c.j <<"i" <<endl;
return o;
}
};
void main()
{
Complex c(2,3);
cout <<c;
}
#include <iostream.h>
class Complex
{
private:
int i;
int j;
public:
Complex(int i=0,int j=0)
{
this->i=i;
this->j=j;
}
friend ostream & operator << ( ostream & o, const Complex & c);
};
ostream & operator << ( ostream & o, const Complex & c)
{
o << c.i << "+" << c.j << "i" << endl;
return o;
}
void main()
{
Complex c(2,3);
cout << c;
}