#include"iostream"
/**************************
析构函数在对象被删除前一刻被调用
无返回值,不接受任何参数
****************************/
using namespace std;
class point
{
public:
point(int xx,int yy)
{
x=xx;
y=yy;
}
point(point &p);
int getx()
{
return x;
}
~point(){
//析构函数,里面加对象释放前要执行的语句
//对象释放时自动调用
}
int gety()
{
return y;
}
int setx(int xx)
{
x=xx;
}
int sety(int yy)
{
y=yy;
}
private:
int x;
int y;
};
point::point(point &p)
{
x=p.x;
y=p.y;
}
void f(point a)
{
cout<<a.getx()<<endl<<a.gety()<<endl;
}
int main()
{
point a(1,1);
point b=a;
point c(a);
a.setx(5);
a.sety(5);
cout<<a.getx()<<endl<<a.gety()<<endl;
f(a);
return 0;
}
C++析构函数
最新推荐文章于 2023-06-08 00:35:52 发布