4-3-2
1 #include <iostream> 2 using namespace std; 3 class Point 4 { 5 public: 6 Point(int xx=0,int yy=0) 7 { 8 x=xx; 9 y=yy; 10 cout<<"Constructor is called"<<endl; 11 } 12 Point(Point &p); 13 int getX() 14 { 15 return x; 16 } 17 int getY() 18 { 19 return y; 20 } 21 private://number(编号)、sex(性别)、birthday(出生日期)、id(身份证号) 22 int x,y; 23 }; 24 Point::Point(Point &p) 25 { 26 x=p.x; 27 y=p.y; 28 cout<<"Calling the copy constructor"<<endl; 29 } 30 31 void f(Point p) 32 { 33 cout<<p.getX()<<endl; 34 } 35 36 Point g() 37 { 38 Point a(1,2); 39 return a; 40 } 41 int main() 42 { 43 cout<<"Point a(1,2);"<<endl; 44 Point a(1,2); 45 cout<<"Point b(a);"<<endl; 46 Point b(a); 47 cout<<"Point c=a;"<<endl; 48 Point c=a; 49 cout<<"f(a);"<<endl; 50 f(a); 51 cout<<"c=g();"<<endl; 52 c=g(); 53 return 0; 54 }
不要让今天成为明天的遗憾!