//重载 operator [] 就可以了
#include
using namespace std;
class point {
private:
int x, y;
public:
static int count;
point(int xx, int yy) :x(xx), y(yy) { count++; }
point() { count++; }
};
class ArrPoint
{
private:
int size;
point* p;
public:
ArrPoint(int s)
{
p = new point[s];
size = s;
}
point& operator [](int i)
{
if(i >= size)
{
// 越界处理
}
return p[i];
}
};
int main()
{
ArrPoint a(5);
a[0], a[1], a[2], a[3], a[4];
return 0;
}
point Arrey[5];
或者
point* Ppoint = new point[5];