constructors and destructors
A constructor is a method that gets called immediately when an object is allocated (on the stack or the heap).
It is the constructor’s job to initialize the object’s attributes to sensible initial values.
A constructor may have parameters that can inform the initial values. A constructor has the same name as the class.
You can have more than one constructor.
A constructor has no return type and no return statement.
C++ gives every class a default (implicit) constructor that takes no arguments, and does nothing.
A destructor is a method that gets called immediately when an object is de-allocated.
It is the destructor’s job tidy up. It may need to deallocate memory on the heap, or close a file.
A destructor may not have parameters.
A destructor has the same name as the class, preceded with a “∼”. You can have only one constructor.
A constructor has no return type and no return statement.
C++ gives every class a default (implicit) destructor that does nothing.
class Point
{
// sample class private:
float x; // stores the x coordinate
float y; // stores the y coordinate
public:
Point(); //the constructor
void setX(float newX);
void setY(float newY);
float getX();
float getY();
~Point(); //the destructor
};
Point::Point()
{
x = 0;
y = 0;
}
Point::~Point()
{
//do nothing
}
constructors and destructors的更多相关文章
- C++ std::array
std::array template < class T, size_t N > class array; Code Example #include <iostream> ...
- Google C++ Style Guide
Background C++ is one of the main development languages used by many of Google's open-source project ...
- Devexpress 等待窗体
加载窗体以及等待窗体 程序加载时,需要等待加载完成后在显示 窗体显示顺序 1. 给用户看的等待窗体 2. 加载完成后的主窗体 代码如下: 1. 等待窗体代码 #region using using S ...
- 【源码笔记】BlogEngine.Net 中的权限管理
BlogEngine.Net 是个功能点很全面的开源博客系统,容易安装和实现定制,开放接口支持TrackBack,可以定义主题配置数据源等等.可谓五脏俱全,这里先记录一下它基于Membership的权 ...
- [Under the hood]---Matt Pietrek October 1996 MSJ
Matt Pietrek October 1996 MSJ Matt Pietrek is the author of Windows 95 System Programming Secrets (I ...
- [under the hood]Reduce EXE and DLL Size with LIBCTINY.LIB
Matt Pietrek Download the code for this article: Hood0101.exe (45KB) W ay back in my October 1996 co ...
- C++ Copy Elision
故事得从 copy/move constructor 说起: The default constructor (12.1), copy constructor and copy assignment ...
- 定制Asp.NET 5 MVC内建身份验证机制 - 基于自建SQL Server用户/角色数据表的表单身份验证
背景 在需要进行表单认证的Asp.NET 5 MVC项目被创建后,往往需要根据项目的实际需求做一系列的工作对MVC 5内建的身份验证机制(Asp.NET Identity)进行扩展和定制: Asp.N ...
- C# 键盘钩子类
键盘钩子类代码如下 class globalKeyboardHook { #region Constant, Structure and Delegate Definitions /// <su ...
随机推荐
- python3中的range函数
奇怪的现象 在paython3中 print(range(10)) 得出的结果是 range(0,10) ,而不是[0,1,2,3,4,5,6,7,8,9] ,为什么呢? 官网原话: In many ...
- 学习Microsoft SQL Server 2008技术内幕:T-SQL语法基础--第4章
第4章 子查询 4.2.1 Exist 谓语: use TSQLFundamentals2008 select * from Sales.Customers as C where c.country= ...
- vs生成命令和属性的宏
在vs属性页面中编辑后期生成事件... 下面是vs中宏的描述信息. http://i.cnblogs.com/EditPosts.aspx?opt=1 高级用法: 磨刀不误砍柴工——VS生成事件
- faststone 注册码
用户名:c1ikm密码:AXMQX-RMMMJ-DBHHF-WIHTV 或 AXOQS-RRMGS-ODAQO-APHUU
- Intellij IDEA错误识别.xml文件
转自原文Intellij IDEA错误识别文件 今天上午弄了一个多小时,对idea感到十分的沮丧,真是太不好用了,一点儿都不智能,而且有些地方,还被自动的配置错误,导致操作起来就像是脱缰的野马. 言归 ...
- 【AS3 Coder】任务四:噪音的魅力(上)
使用框架:AS3任务描述:使用AS3中BitmapData的noise方法以及perlinNoise方法构建自然景观效果以及其他一些比较cool的效果难度系数:2 本文章源码下载:www.iamsev ...
- ILockBytes Windows Mobile 6.5
ILockBytes Windows Mobile 6.5 https://msdn.microsoft.com/zh-cn/library/aa911496(en-us,MSDN.10).aspx ...
- 作为Java程序员应该掌握的10项技能
本文详细罗列了作为Java程序员应该掌握的10项技能.分享给大家供大家参考.具体如下: 1.语法:必须比较熟悉,在写代码的时候IDE的编辑器对某一行报错应该能够根据报错信息知道是什么样的语法错误并且知 ...
- Web学习篇之---css基础知识(一)
css基础知识(一) 1.css样式: 载入css样式有下面四种: 1).外部样式 2).内部样式 3).行内样式 4).导入样式 <link href="layout.css&quo ...
- 创建支持多种屏幕尺寸的apk
文章转至:http://hell0android.iteye.com/blog/1899605 创建对两种以上屏幕尺寸的多apk支持(Creating Multiple APKs with 2+ Di ...