C++的构造函数与析构函数:#include <iostream> using namespace std; class Point{ private : int x,y; public : Point(int a=0 ,int b=0) { x=a; y=b; cout<<"Initializing"<<endl; } Point(const Point &p); /* *获取私有参数x,y */ int getX(){return x;} int getY(){return y;} void show() { cout<<"X="<<x<<",Y="<<y<<endl; } //Define the destruct ~Point() { cout<<"Delete..."<<x<<",Y= "<<y<<endl; } }; Point::Point(const Point &p) { x =p.x; y =p.y; cout<<"Copy Initializing"<<endl; } //Point 类的对象作为对象函数的参数 void display(Point p) { p.show(); } //Point 类的对象的应用作为对象函数的参数 /* *使用应用作为函数的参数时,不需要调用复制的构造函数 */ void disp(Point &p) { p.show(); } /* *当返回A对象给C,调用析构函数清除临时对象A *当对出函数的时候,调用析构函数清除对象A */ Point fun() { Point A(100,202); return A; } void main() { Point A(42,35);//对象A //第一次调用复制构造函数 Point B(A); //(1)用A 初始化B Point C(58,94); cout<<"Called display(B) "<<endl; /* *对出函数体display(Point p)时,会调用析构函数清除对象 */ display(B); //第二次复制构造函数 cout<<"Next ..."<<endl; cout<<"Called disp(B) "<<endl; disp(B); cout<<"Call C =fun()"<<endl; //第三次调用复制构造函数 C =fun(); //(3)fun 的返回值赋给对象C cout<<"Called disp(C) "<<endl; disp(C); cout<<"out..."<<endl; } 想一想,结果是怎样的。 可以检测你的C++构造函数与析构函数的掌握程度与具体的精度。