错误!xcor 在 setAll() 函数中未声明
我已经在 Circle 类中创建了 PointType 的对象来进行某种组合,但是在 Circle 的构造函数的初始化中,它表明
“ [错误] 'ycor' 未在此范围内声明”
“ [错误] 'xcor' 未在此范围内声明”
我想在我的 Circle 类中使用 xcor 和 ycor 以便使用 setAll() 函数获取半径
请帮忙!我在搞砸什么。
#include<iostream>
#include<cstdlib>
#include<cmath>
using namespace std;
class PointType{
private:
int xcor;//x coordinate
int ycor;//y coordinate
public:
PointType();//constructor
PointType(int x,int y);
void setPoint(int x,int y);
int getx() const;
int gety() const;
};
PointType::PointType():xcor(0),ycor(0)
{
}
PointType::PointType(int x,int y):xcor(x),ycor(y){
}
void PointType::setPoint(int x,int y){
xcor=x;
ycor=y;
}
int PointType::getx() const{
return xcor;
}
int PointType::gety() const{
return ycor;
}
class Circle{
protected:
float Radius;
float Area;
int Circumference;
float pi;
PointType obj1;
public:
Circle();
void setAll();
float getRadius();
float getArea();
float getCircumference();
void callFunction();
void printAll();
void pt(int x,int y);
};
Circle::Circle():Radius(0),Area(0),Circumference(0),pi(3.1415),obj1(xcor,ycor){
}
void Circle::setAll(){
Radius=sqrt( (xcor*xcor) + (ycor*ycor) );
Area=pi*Radius*Radius;
Circumference=2*pi*Radius;
}
float Circle::getRadius(){
return Radius;
}
float Circle::getArea(){
return Area;
}
float Circle::getCircumference(){
return Circumference;
}
void Circle::printAll(){
cout<<"The Area is :"<<Area<<endl;
cout<<"The Circumference is :"<<Circumference<<endl;
}
void Circle::pt(int x,int y){
obj1.setPoint(x,y);
}