标题:大虾帮忙,明天就要考试了
只看楼主
cxwl3sxl
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:495
专家分:129
注 册:2005-11-12
结帖率:100%
 问题点数:0 回复次数:0 
大虾帮忙,明天就要考试了

#include<iostream.h>
class Point
{ 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; }
private:
int X,Y;
};
class ArrayOfPoints
{
public:
ArrayOfPoints(int n)
{ numberOfPoints=n; points=new Point[n]; }
~ArrayOfPoints()
{ cout<<"Deleting..."<<endl;
numberOfPoints=0; delete[] points;
}
Point& Element(int n) //这里的“&”是什么啊?
{ return points[n]; }
private:
Point *points;
int numberOfPoints;
};

int main()
{
int number;
cout<<"Please enter the number of points:";
cin>>number;
ArrayOfPoints points(number); //创建对象数组
points.Element(0).Move(5,10); //通过指针访问数组元素的成员
points.Element(1).Move(15,20); //通过指针访问数组元素的成员
}

搜索更多相关主题的帖子: 考试 
2005-12-26 22:02



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-40102-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017607 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved