请教一个点运算符方面的报错。
#include<iostream>using namespace std;
class Point //定义点类,成员变量为平面内两个坐标值
{
public:
void SetPos(int m, int n){x=m;y=n;}
int GetX(){return x;}
int GetY(){return y;}
private:
int x; int y;
};
class Circle //定义圆形类,成员变量一为点类的圆心,一为整型的半径
{
public:
Circle
Circle(Point, double);
Circle(int, int, double);
~Circle(){};
void SetCenter(Point c){Center=c;}
void SetRadius(double r){Radius=r;}
Point GetCenter(){return Center;}
double GetRadius(){return Radius;}
private:
Point Center;
double Radius;
};
Circle::Circle()
{
Point p;p.SetPos(0,0);SetCenter(p);SetRadius(10);
}
Circle::Circle(Point c, double r)
{
SetCenter(c);SetRadius(r);
}
Circle::Circle(int x=0, int y=0, double r=10)
{
Point p;
p.SetPos(x,y);
SetCenter(p);
SetRadius(r);
}
void main()
{
Circle MyCircle();
cout<<"圆的坐标:"<<(MyCircle().GetCenter).GetX<<endl;
//报错就在上面这行,说是error C2228: left of '.GetX' must have class/struct/union type
//执行 cl.exe 时出错.
}
为什么它不承认这里的(MyCircle().GetCenter)是一个Point类呢?我试了在GetX后加上()还是一样的报错。请各位老师帮忙看一看。谢谢。