#include<bits/stdc++.h>
using namespace std;
/**
* 对象数组和对象指针
* */
class Point {
int x, y;
public:
Point() {
x = 1;
y = 1;
}
Point(int a, int b = 10) {
x = a;
y = b;
}
int getX() {
return x;
}
int getY() {
return y;
}
};
int main() {
Point p1(3, 3);
Point p[3]; // 由于有无参构造函数,可以定义对象数组
Point *pt;
for(int i = 0; i <= 2; i++) {
// cout<<"p["<<i<<"].x="<<p[i].getX()<<"\t";
// cout<<"p["<<i<<"].y="<<p[i].getY()<<endl;
printf("p[%d].x=%d \t p[%d].y=%d\n", i, p[i].getX(), i, p[i].getY());
}
pt = &p1;
printf("Point pt->x=%d\n", pt->getX());
pt = p;
printf("Point array pt->x=%d\n", pt->getX());
pt++;
printf("Point array pt->x=%d\n", pt->getX());
printf("Point (*pt).x=%d\n", (*pt).getX());
return 0;
}