class Point{
double x,y;
public:
Point():x(0),y(0){};
void Set(double a, double b){
x=a;
y=b;
}
double GetX(){
return x;
}
double GetY(){
return y;
}
void Show(Point*q){
cout<<"("<<q->GetX<<","<<q->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++);
}
system("pause");
return 0;
}
};
#include <iostream>
using namespace std;
错误比较多,修改如下:
#include <iostream>
using namespace std;
class Point{
double x,y;
public:
Point():x(0),y(0){};
Point(double x1,double y1) {x=x1;y=y1;}
void Set(double a, double b){
x=a;
y=b;
}
double GetX(){
return x;
}
double GetY(){
return y;
}
};
void Show(Point*q)
{
cout<<"("<<q->GetX()<<","<<q->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;
}
22行后面少了个分号,还有你也没有相应的构造函数
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!