问题遇到的现象和发生背景
不会定义数组a
问题相关代码,请勿粘贴截图
#include <iostream>
using namespace std;
class Point{ //定义类Point
double x,y; //有两个变量
public:
Point(double x0,double y0) :x(x0),y(y0){};
Point():x(0),y(0){};
void Set(double a, double b)
{
x=a;
y=b;
}
double GetX(){//返回x和y的值
return x;
}
double GetY(){
return y;
}
};
void Show(Point[],a)
{
for(int i=0;i<5;i++)
cout<<"("<<a[i].GetX()<<","<<a[i].GetY()<<")";
}
///////////////////////////////////////////////////////
int main()
{
Point a[5]={Point(0,0),Point(1,1),Point(2,2),Point(3,3),Point(4,4)};
Point*p=a;
p->Set(5,9);
a[3].Set(6,8);
for (int i=0; i<5; i++){
Show(p++);
}
return 0;
}