C++学习(6)
1 //析构函数的学习 2 #include<iostream.h> 3 class Point{ 4 private: 5 int x; 6 int y; 7 public: 8 Point(){} 9 Point(int x,int y){ 10 this->x=x; 11 this->y=y; 12 cout<<"Point类构造函数调用"<<endl; 13 } 14 Point(Point &c){ 15 this->x=c.x; 16 this->y=c.y; 17 cout<<"point类构造函数调用"<<endl; 18 } 19 ~Point(){ 20 cout<<"point类析构函数调用"<<endl; 21 } 22 }; 23 24 class Line{ 25 private: 26 Point a; 27 Point b; 28 public: 29 Line(){} 30 Line(int x1,int y1,int x2,int y2):a(x1,y1),b(x2,y2){//似乎调用构造函数只能这样调用???? 31 // a(x1,y1); 32 // this->b(x2,y2); 33 cout<<"Line类构造函数1调用"<<endl; 34 } 35 Line(Point &a,Point &b){ 36 this->a=a; 37 this->b=b; 38 cout<<"Line类构造函数2调用"<<endl; 39 } 40 ~Line(){ 41 cout<<"Line类析构函数调用"<<endl; 42 } 43 }; 44 45 46 int main(){ 47 cout<<"构造函数调用过程"<<endl; 48 Line myLine(1,1,5,5); 49 return 0; 50 }
posted on 2018-06-29 18:49 孙悟空son_ku_kong 阅读(110) 评论(0) 编辑 收藏 举报