f0805.cpp
资源名称:c.rar [点击查看]
上传用户:puke2000
上传日期:2022-07-25
资源大小:912k
文件大小:1k
源码类别:
C#编程
开发平台:
Visual C++
- //==================================
- // f0805.cpp
- // overload operator
- //==================================
- #include<iostream>
- using namespace std;
- //----------------------------------
- class Point{
- int x, y;
- public:
- void set(int a, int b){ x=a, y=b; }
- void print()const{ cout<<"("<<x<<", "<<y<<")n"; }
- friend Point operator+(const Point& a, const Point& b);
- friend Point add(const Point& a, const Point& b);
- };//===============================
- Point operator+(const Point& a, const Point& b){
- Point s;
- s.set(a.x+b.x, a.y+b.y);
- return s;
- }//--------------------------------
- Point add(const Point& a, const Point& b){
- Point s;
- s.set(a.x+b.x, a.y+b.y);
- return s;
- }//--------------------------------
- int main(){
- Point a, b;
- a.set(3,2);
- b.set(1,5);
- (a+b).print();
- operator+(a,b).print();
- add(a, b).print();
- }//================================