//188 6_17.cpp
#include <iostream>
using namespace std; //动态创建对象数组
class point
{
private:
int X, Y;
public:
point(){ X = Y = 0; cout << "default constructor called" << endl; }
point(int xx, int yy){ X = xx; Y = yy; cout << "constructor called" << endl; }
~point(){ cout << "destructor called" << endl; }
int getx(){ return X; }
int gety(){ return Y; }
void move(int x, int y){ X = x; Y = y; }
};
class arrayofpoints
{
public:
arrayofpoints(int n)
{
numberofpoints = n;
points = new point[n];
}
point&element(int n)
{
return points[n];
}
private:
point*points;
int numberofpoints;
};
int main()
{
int number;
cin >> number;
arrayofpoints points(number);
points.element(0).move(5, 10);
points.element(1).move(15, 20);
system("pause");
return 0;
}
动态数组类
最新推荐文章于 2020-03-25 22:50:19 发布