title: Subclass getting superclass private variables c++
body: <p>I've got a superclass which has certain private variables, and I need to build a constructor for a subclass. Here's the superclass:</p>
  
  <pre><code>class Shape {
  public:
      Shape(double w, double h);
      string toString();
  
  private:
      double width;
      double height;
  
  };
  </code></pre>
  
  <p>Superclass constructor:</p>
  
  <pre><code>Shape::Shape(double w, double h) {
      width = w;
      height = h;
  }
  </code></pre>
  
  <p>Subclass:</p>
  
  <pre><code>class Rectangle : public Shape {
  
  public:
      Rectangle(double w, double h, int s);
      string toString();
  
  private:
      int sides;
  
  };
  </code></pre>
  
  <p>My subclass constructor is as follows:</p>
  
  <pre><code>Rectangle::Rectangle(double w, double h, int s) : Shape(w, h) {
  
      width = w;
      height = h;
      sides = s;
  
  }
  </code></pre>
  
  <p>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.</p>