基本クラスと子クラスの関数の継承について非常に混乱しています。私はそれらのクラスを持っています:
#include <point.h>
class Polygon{
public:
Polygon();
virtual ~Polygon();
void addPoint(Point *p);
std::string getType();
Point* getPoint(int index);
int getNumOfPoints();
int getColor();
virtual int area()=0;
private:
std::vector<Point*> _points;
int color;
std::string type = "Polygon";
};
class Rectangle : public Polygon{
public:
Rectangle();
virtual ~Rectangle();
virtual int area();
private:
std::vector<Point*> _points;
int color;
std::string type = "Rectangle";
};
さて、主に私はこれを行います:
Rectangle rect();
rect.getType();
これにより「ポリゴン」が得られますが、「長方形」が必要です。継承と混同していると確信しています。したがって、私の理解によると、基本クラスの関数は継承されますが、関数を実行すると、実際のオブジェクト (Rectangle) ではなく、オブジェクトの基本クラスのメンバーに関連するのはなぜですか?
誰かが助けてくれたら嬉しいです!とても有難い