C++析构函数
发布日期:2021-05-07 10:13:19 浏览次数:20 分类:原创文章

本文共 1064 字,大约阅读时间需要 3 分钟。

#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++组合类
下一篇:C++前向引用声明

发表评论

最新留言

表示我来过!
[***.240.166.169]2025年04月02日 05时38分56秒