您的位置:首页 > 其它

对象数组

2016-04-09 19:31 218 查看
#include<iostream>
using namespace std;
class Point {
public:
Point() : _x(0), _y(0) {};
Point(int x, int y) : _x(x), _y(y) {};
~Point() {};
void setX(int x){ _x = x; }
void setY(int y){ _y = y; }
int getX() const { return _x; }
int getY() const { return _y; }
private:
int _x, _y;
};
int main()
{
Point *ptr=new Point[5];
for(int i=0;i<5;i++)
{
int xx,yy;
cin>>xx>>yy;
ptr[i].setX(xx),ptr[i].setY(yy);
cout<<ptr[i].getX()<<'\t'<<ptr[i].getY()<<endl;;
}
delete []ptr;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: