2012-04-10 4 views
0

エラー!XCOR SETALLで宣言されていない()関数C++作曲プログラムエラー(XCOR宣言されていない)

私は、組成物の並べ替えを行うにはCircleクラスで点種のオブジェクトを作成していたが、サークルのコンストラクタの初期化時にそれがあります

は、私は私のサークルでXCORとycorをしたい「[エラー] 『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); 

} 

答えて

0

あなたのクラスCirclexcorまたはと呼ばれる任意のメンバ変数を持っていません。あなたはPointTypeオブジェクトの値を取得したい場合は、あなたのsetAll関数は次のようになります。それはいずれかへのアクセスを持っていないよう

Circle::Circle():Radius(0),Area(0),Circumference(0),pi(3.1415),obj1(0,0) 

Radius=sqrt( (obj1.getx()*obj1.getx()) + (obj1.gety()*obj1.gety()) ); 

また、あなたはあなたのコンストラクタを変更する必要がありますxcorまたはです。

0

宣言XCOR、ycorサークル」コンストラクタ引数、および

までの半径を計算する前に次の行を追加します。

int xcor = obj1.getx(), ycor = obj1.gety(); 
Radius=sqrt( (xcor*xcor) + (ycor*ycor) ); 

また、代わりに埋め込まれたOBJ1の、サークルのための点種を継承するために考えることができます:

class Circle : public PointType 
{ 
public: Circle(int x, int y):PointType(x, y) {} 
... 
/* remove obj1 */ 
} 
0
  1. Circleコンストラクタを変更する必要があります。これは、k XCORとycorについて何もNowsのない:

    Circle::Circle():Radius(0),Area(0),Circumference(0),pi(3.1415),obj1(42,56)

  2. あなたがSETALL方法を変更する必要がありますのでCircleクラスはまだ、XCORとycorについて知らない:

    Radius=sqrt( static_cast<double>((obj1.getx()*obj1.getx()) + (obj1.gety()*obj1.gety())) );

関連する問題