
本文共 2770 字,大约阅读时间需要 9 分钟。
���C++������new
���������������������������������������������������������������������������������������������������new
���������������������������������������
new ��������� [������������];
���������
int* arr = new int[10];
������������������������������������������������������[]
���������������������������[]
������������������������������������������������[]
���������new ���������
���������������������������������������������������������������������������������������������������
int* arr = new int;
������������������new ��������� [������������]
���������������������������������������������������������������������������������������������������������������������������������new ��������� [������������]()
���������������������������������������������()
������������������������������������������������new ��������� [������������]
���������������������
���������������������������������������������������������������������������������������������������������delete[]
���������������������������������������������
delete[] arr;
���������������delete
���������������������������[]
���������������������������[]
������������������������������������������
delete arr; // ������������������������������delete[] arr; // ���������������������������
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������
#includeusing namespace std;class Point {private: int x, y;public: Point() : x(0), y(0) { cout << "������������������������." << endl; } Point(int x, int y) : x(x), y(y) { cout << "������������������������." << endl; } ~Point() { cout << "������������������." << endl; } int getX() const { return x; } int getY() const { return y; } void move(int x, int y) { this->x = x; this->y = y; }};int main() { Point* point = new Point[2]; // ������������������ // ���������������������Point* point = new Point[2]() point[0].move(25, 15); // ��������������������������������������� point[1].move(35, 45); // ��������������������������������������� delete[] point; // ������������������������ return 0;}
���������new
������������������������������������������������
[]
������������������������������������delete[]
������������������()
���������������������������������������������������������������������������������������������������������new
���delete
������������������������������������������������������������������������unique_ptr
���������������������������������������