f0807.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:

C#编程

开发平台:

Visual C++

  1. //=====================================
  2. // f0807.cpp
  3. // member & non-member operator
  4. //=====================================
  5. #include<iostream>
  6. using namespace std;
  7. //-------------------------------------
  8. class Point{
  9.   int x, y;
  10. public:
  11.   void set(int a, int b){ x=a, y=b; }
  12.   Point operator+(const Point& d){
  13.     Point s;
  14.     s.set(x+d.x, y+d.y);
  15.     return s;
  16.   }//----------------------------------
  17.   friend ostream& operator<<(ostream& o, const Point& d);
  18. };//===================================
  19. inline ostream& operator<<(ostream& o, const Point& d){
  20.   return o<<"("<<d.x<<","<<d.y<<")n";
  21. }//====================================
  22. int main(){
  23.   Point s,t;
  24.   s.set(2,5);
  25.   t.set(3,1);
  26.   cout<<s+t;
  27. }//====================================
  28.