C++动态数组的创建及应用

本文深入探讨了C++中的动态数组,包括如何使用new运算符创建动态数组,理解内存管理和释放数组的方法,以及在实际编程中动态数组的应用场景和最佳实践。通过实例解析动态数组的优势和使用技巧。
摘要由CSDN通过智能技术生成
/*---------------------------------------
功能:动态数组的创建和应用
运行结果:
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; } // 析构函数
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值