跳至正文
-
Subscribe to our newsletter & never miss our best posts. Subscribe Now!
小奥的学习笔记

万丈高楼平地起,勿在浮沙筑高台

小奥的学习笔记

万丈高楼平地起,勿在浮沙筑高台

  • 首页
  • Sample Page
  • 隐私策略
  • GuestBook
  • 慕课课程(MOOC’s Lessons)
  • Footprints
  • About Me
  • 个人履历
  • 首页
  • Sample Page
  • 隐私策略
  • GuestBook
  • 慕课课程(MOOC’s Lessons)
  • Footprints
  • About Me
  • 个人履历
关

搜索

  • https://www.facebook.com/
  • https://twitter.com/
  • https://t.me/
  • https://www.instagram.com/
  • https://youtube.com/
Subscribe
C/C++MOOC

第四章:类与对象(三)析构函数

作者 yszhang
2015年4月8日 1 分钟阅读
0

析构函数完成对象被删除前的一些清理工作。比如说因为这个对象打开了一个文件,那么用了这个就可以关闭文件。在对象生存期结束之时,系统自动调用析构函数。如果程序中未定义析构函数,则编译器自动产生一个默认的析构函数,它的函数体是空的,我们可以简单认为它是什么都不做的。语法规定了构造函数时一定需要一个构造函数,删除的时候一定要构造一个析构函数,这是为什么我们不定义,系统也会给我们定义构造函数和析构函数。

析构函数原型:

~ 类名;

析构函数没有参数,没有返回值类型。

例如:

class Point

{

public:

Point(int xx, int yy);

~Point();

private:

int hour;

};

Point::Point(int xx, int yy)

{

内容

}

Point::~Point(){ }

作者

yszhang

关注我
其他文章
上一个

C++递归用法

下一个

全国大学生英语四六级口语考生手册

暂无评论!成为第一个。

发表回复 取消回复

您的邮箱地址不会被公开。 必填项已用 * 标注

Copyright 2026 — 小奥的学习笔记. All rights reserved. Blogsy WordPress Theme