コンストラクター (名前、幅、高さ) で同じ引数を持つ Rectangle クラスと Square クラスがあります。
そこで、Shape という Base クラスを作成し、Shape.h にコンストラクターを定義して、Rectangle クラスと Square クラスに Shape クラスからコンストラクターを継承させることを考えました。
私が直面している問題は、コンストラクターを Shape クラスから Rectangle および Square クラスに継承する方法がよくわからないことです。
私はまだC++に慣れていないので、簡単な質問をしている場合はご容赦ください。
シェイプ.h
#include <iostream>
#ifndef Assn2_Shape_h
#define Assn2_Shape_h
class Shape {
public:
Shape() {
name = " ";
width = 0;
height = 0;
}
Shape(std::string name, double width, double height);
private:
std::string name;
double width,height;
};
#endif
Rectangle.h
#include <iostream>
#ifndef Assn2_Rectangle_h
#define Assn2_Rectangle_h
class Rectangle : public Shape {
//how to inherit the constructor from Shape class?
public:
Rectangle() {
}
private:
};
#endif
Square.h
#include <iostream>
#ifndef Assn2_Square_h
#define Assn2_Square_h
class Square: public Shape {
//how to inherit the constructor from Shape class?
public:
Square() {
}
private:
};
#endif