标签:
1 #include <iostream> 2 using namespace std; 3 4 class TPoint 5 { 6 public: 7 TPoint() 8 { 9 X=0; 10 Y=0; 11 cout<<"无参数构造函数"<<endl; 12 } 13 14 TPoint(int x,int y) 15 { 16 X=x; 17 Y=y; 18 cout<<"带参数构造函数"<<endl; 19 } 20 21 TPoint &operator = (const TPoint ¶m) 22 { 23 X=param.X; 24 Y=param.Y; 25 cout<<"赋值运算"<<endl; 26 return *this; 27 } 28 29 TPoint(TPoint &p); 30 31 ~TPoint() { cout<<"Destructor\n"; } 32 33 int Xcoord() { return X; } 34 int Ycoord() { return Y; } 35 36 private: 37 int X,Y; 38 }; 39 40 TPoint::TPoint(TPoint &p) 41 { 42 X=p.X; 43 Y=p.Y; 44 cout<<"copy_constructor\n"; 45 } 46 47 TPoint f(TPoint Q) 48 { 49 cout << endl; 50 cout<<"f函数开始\n"; 51 int x,y; 52 x = Q.Xcoord()+10; 53 y = Q.Ycoord()+20; 54 TPoint R(x,y); 55 return R; 56 } 57 58 void main() 59 { 60 TPoint M(20,35),P(0,0); 61 cout<<"M和P"<<endl; 62 TPoint N(M); 63 cout<<"N"<<endl; 64 P = f(N); 65 cout<<"f函数"<<endl; 66 cout<<"P="<<P.Xcoord()<<","<<P.Ycoord()<<endl; 67 cout<<"main结束?"<<endl; 68 }
标签:
原文地址:http://www.cnblogs.com/youngqq-16/p/5857826.html