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
}
最新文章
- ORACLE导入导出数据dmp
- Oracle数据库的导入导出
- Father Christmas flymouse--POJ3160Tarjan
- UESTC 395 Dynamic Query System --Treap
- Java学习-043-获取文件在目录中的路径
- Codeforces 720A. Closing ceremony
- 浅谈对ECharts的使用
- leetcode:Valid Parentheses
- 使用Redis做MyBatis的二级缓存
- Angularjs总结(二)过滤器使用
- javascript——闭包
- .bind.apply() 解决 new 操作符不能用与 apply 或 call 同时使用
- webpack打包vue
- IE浏览器解决无法识别js中getElementsByClassName问题
- js 构建map 和list
- 八一八cvs vss svn和git比较
- Publish to a Linux Production Environment
- SSH连接与自动化部署工具paramiko与Fabric
- ZooKeeper学习2---ZooKeeper安装配置
- wifi设置
热门文章
- jvm-监控指令-jstack
- 阿里云(ECS)Linux客户端SSH会话连接超时OperationTimedOut
- Saga的实现模式——进化(Saga implementation patterns – variations)
- MathType如何插入连乘
- 更合理的 setState()
- git如何打补丁?
- Java笔记4:JDBC纯驱动方式连接Oracle
- 倍福TwinCAT(贝福Beckhoff)基础教程7.1 TwinCAT 如何简单执行NC功能块 TC3
- NSight统计数据的颜色,缩写意义是什么?来自NV Jeff Kiel 比较官方的解释!
- Oracle,跳出游标循环