C++ 笔记(17)— 类和对象(构造函数、析构函数)
发布日期:2021-05-10 08:43:59 浏览次数:11 分类:精选文章

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

���������������������������

���������������C++������������������������������������������������������������������������������������

������������

������������������������������������������������������������������������������������:void������������������������������������������������������������

������������������

������������������������������������������������������������������������������������������������������

Line(){    cout << "Object is being created" << endl;}

������������������������������

Line Line() {    cout << "Object is being created" << endl;}

���������C++���������������������������������public������������������

������������������������

������������������������������������������������������������������������������������������������

Line(double len){    cout << "Object is being created, length = " << len << endl;    length = len;}

������������������������������������������������

������������������������������

������������������������������������������������������������������������������������������������������

Line(double len = 20.0){    cout << "Object is being created, length = " << len << endl;    length = len;}

���������������������������������������������������

���������������

���������������������������������������������������������������������������

Line(double len) : length(len){    cout << "Object is being created, length = " << len << endl;}

���������������������������

Line(double len){    length = len;    cout << "Object is being created, length = " << len << endl;}

���������������������������������������������������������������

������������

������������������������������������������������������������������������~���������������������������������������

���������������������������

������������������������������������������

Line::~Line(){    cout << "Object is being deleted" << endl;}

������������������������������������������������������������

������������������

������������������������������������������������������������������������������������

Line line;// ������������line.setLength(6.0);cout << "Length of line : " << line.getLength() << endl;// ������������������������������������������������
Line line;Line::~Line();

���������������line������������������������������

上一篇:C++ 笔记(18)— 类和对象(this 指针、指向类的指针、类静态成员变量和函数)
下一篇:C++ 笔记(15)— 引用(声明引用、引用作为参数、引用作为函数返回值、const 用于引用)

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2025年04月15日 07时35分50秒