私は私のクラスに大きな四角形を作成するために、派生クラス「RECTANGLE」と私は、基本クラスの内部で持っている機能「SHAPE」を使用しようとしている「BIGRECTANGLE」。私はクラスの中で私の側の変換をしたいと主なものではない、私は何をすべきですか?ありがとう!ネストされたクラスと継承
#include <iostream>
using namespace std;
// Base class Shape
class Shape
{
public:
void ResizeW(int w)
{
width = w;
}
void ResizeH(int h)
{
height = h;
}
protected:
int width;
int height;
};
// Primitive Shape
class Rectangle: public Shape
{
public:
int width = 2;
int height = 1;
int getArea()
{
return (width * height);
}
};
// Derived class
class BIGRectangle: public Rectangle
{
public:
int area;
Rectangle.ResizeW(8);
Rectangle.ResizeH(4);
area = Rectangle.getArea();
};
int main(void)
{
return 0;
}
はこれらは私が持っているエラーです: - 45:14:エラー:予想される修飾されていない-IDの前に ''トークン - 46:14:エラー: '。'の前にunqualified-idが必要ですトークン - 47:5:エラー:「面積」はタイプ
コンストラクタなどに入れてください...コンストラクタは何ですか?あなたはそれらを使用していません。 – LogicStuff
@LogicStuffあなたは私に理解を助けることができますか? – FL93
コンストラクタに関する[チュートリアル](http://www.cplusplus.com/doc/tutorial/classes/)へのリンクです。また、[継承](https:// www。cs.bu.edu/teaching/cpp/inheritance/intro/)。それらを読みます; Googleはあなたの友人です。 – NonCreature0714