<pre name="code" class="cpp">#include "stdafx.h"
#include<iostream>
using namespace std;
class Point
{
int x,y;
public:
Point(int x1=0,int y1=0){x=x1;y=y1;}
friend istream & operator >>(istream & input,Point & obj);
friend ostream & operator <<(ostream & output,Point & obj);
};
istream & operator >>(istream & input,Point & obj)
{
cout<<"input x,y of point:";
input>>obj.x>>obj.y;
return input;
}
ostream & operator <<(ostream & output,Point & obj)
{
cout<<"output x,y of point:";
output<<"x="<<obj.x<<"y="<<obj.y<<"\n";
return output;
}
void main()
{
Point obj1,obj2;
cin>>obj1>>obj2;
cout<<obj1<<obj2;
}
(三 )运算符重载
最新推荐文章于 2023-11-19 00:15:00 发布