#include <iostream>
using namespace std;
class Coordinate
{
public:
Coordinate(){};
~Coordinate(){};
int x;
int y;
};
int main()
{
Coordinate *const coor = new Coordinate[3]; 定义 coor 为const型,所以coor指向不会变
coor->x = 3; 执行 coor++的时候,就会报错,保证了安全性
coor->y = 4;
(coor + 1)->x = 5;
(coor + 1)->y = 6;
for(int i = 0; i < 2; i++)
{
cout << (coor + i)->x << " " << (coor + i)->y << endl;
}
delete []coor; 如果不加[], 则只是删除了第一个申请的对象
coor = NULL;
return 0;
}