title: How to access a private member in the baseclass from a subclass with inheritance ( C++ )
body: <p>I am currently busy with inheritance and I'm working with a base class called <code>Vehicle</code> and a subclass called <code>Truck</code>. The subclass is inheriting from the base class. I am managing with the inheritance of the public members of <code>Vehicle</code> but can't access the private member called <code>top_speed</code> in the function <code>void describe() const</code>.</p>
  
  <p>I know that one can do this in code (provided below) to access from the base class but it seems like I'm missing something. In the comment section in the code my question is stated more clearly for you.</p>
  
  <pre><code>void Truck::describe() const : Vehicle()  
  
  /*I know this is a way-&gt;    : Vehicle() 
  to inherit from the Vehicle class but how
  can I inherit the top_speed private member of Vehicle in the
  void describe() const function of the Truck class?*/
  
  {
      cout &lt;&lt; "This is a Truck with top speed of" &lt;&lt; top_speed &lt;&lt; 
      "and load capacity of " &lt;&lt; load_capacity &lt;&lt; endl;
  }
  </code></pre>
  
  <p>Where in my <code>Vehicle</code> class it is:</p>
  
  <pre><code>class Vehicle
  {
  private:
      double top_speed;
  
  public:
      //other public members
      void describe() const;
  };
  </code></pre>
  
  <p>and in the Truck class it is this:</p>
  
  <pre><code>class Truck: public Vehicle
  {
  private:
      double load_capacity;
  public:
      //other public members
      void describe() const;  
  };
  </code></pre>
  
  <p>To be even more clear I am getting this error: </p>
  
  <pre><code>error: 'double Vehicle::top_speed' is private
  </code></pre>
  
  <p>What can I do in the <strong><code>void Truck::describe() const</code></strong> function to fix it?</p>