I've got a superclass which has certain private variables, and I need to build a constructor for a subclass. Here's the superclass:
class Shape {
public:
Shape(double w, double h);
string toString();
private:
double width;
double height;
};
Superclass constructor:
Shape::Shape(double w, double h) {
width = w;
height = h;
}
Subclass:
class Rectangle : public Shape {
public:
Rectangle(double w, double h, int s);
string toString();
private:
int sides;
};
My subclass constructor is as follows:
Rectangle::Rectangle(double w, double h, int s) : Shape(w, h) {
width = w;
height = h;
sides = s;
}
I cannot modify the superclass at all. All I can do is modify the constructor class to get the values which are private in the superclass.