/*---------------------------------------
功能:动态数组的创建和应用
运行结果:
Input the number of point: 2
Calling default constructor of Point...
Calling default constructor of Point...
Calling constructor of ArrayPoint...
(5, 0)
(15, 12)
Calling destructor of PointArray...
Calling destructor of Point...
Calling destructor of Point...
-----------------------------------------
Author: Zhang Kaizhou
Date: 2019-4-4 17:23:48
----------------------------------------*/
#include <iostream>
using namespace std;
class Point{ // 创建一个点Point类
private:
int x, y;
public:
Point(){ cout << "Calling default constructor of Point..." << endl; } // 默认构造函数
Point(int xx, int yy):x(xx), y(yy){ cout << "Calling parameter constructor of Point..." << endl; } // 含参构造函数
Point(Point & p){ // 复制构造函数
x = p.x;
y = p.y;
}
~Point(){ cout << "Calling destructor of Point..." << endl; } // 析构函数
C++动态数组的创建及应用
最新推荐文章于 2024-08-06 07:43:00 发布
本文深入探讨了C++中的动态数组,包括如何使用new运算符创建动态数组,理解内存管理和释放数组的方法,以及在实际编程中动态数组的应用场景和最佳实践。通过实例解析动态数组的优势和使用技巧。
摘要由CSDN通过智能技术生成