![]() |
#2
lijm19892010-06-03 13:42
|
请看一下程序段,我用红色标出了问题所在
#include <iostream>
using namespace std;
class Point
{
//。。。。。
}
class ArrayOfPoints
{
public:
ArrayOfPoints(int n)
{numberOfPoints=n;points=new Point[n];}
~ ArrayOfPoints()
{cout<<"Deleteting..."<<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;
ArrayOfPoint points(number);
points.Element(0).Move(5,10);
points.Element(1).Move(15,20);
}
C++里面函数类型标识符一般都是int ,float,double,或者是自己定义的类,但是在类型标识符后还有加 “&”那代表什么啊?谁知道?
Point& Element(int n)
{return points[n];}
其中Point是一个类名,但是Point后面加了个“&”,那代表什么啊?