c++书上的一个问题,初学者 请多多指教

#include
using namespace std;
class Point{
public:
Point() :x(0), y(0){
cout << "Constructor called." << endl;
}
~Point(){ cout << "Destructor called." << endl; }
int getX() const{ return x; }
int getY() const{ return y; }
void move(int newX, int newY){
x = newX;
y = newY;
cout << x + y << endl;
}
private:
int x, y;
};
int main(){
Point*ptr = new Point[2];
ptr[0].move(5, 10);
ptr[1].move(15, 20);
cout << "Deleting..." << endl;
delete[] ptr;
system("pause");
return 0;
}

为什么可以通过ptr[0].move(5, 10);
ptr[1].move(15, 20);
这种方式访问数组,就是ptr[0],ptr[1]这种方式

C语言这么规定的。对于指针
p + 1和p[1]是一回事。不但如此,你甚至可以写1[p]这种不可以思议的写法。因为p + 1=1 + p

习惯就好,C/C++语言诞生在几十年前,是非常原始和落后的编程语言。

Point*ptr = new Point[2]; 这个是创建两个point对象数组 而move函数是那个point对象的函数 所以每个对象数组都能调用move函数

数组名加下标就表示数组内对应位置的对象本身,对象当然可以直接通过“.”运算符调用自己的成员函数