求助~~Point&Element(int n)什么意思?
谁能解释下最后的points.Element(0).Move(5,10)是怎么引用的,Point&Element(int n)什么意思?#include <iostream>
using namespace std;
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);
}