Can I pass a child class to a reference of a parent class?
<p>I have a class A which takes a reference of B in its constructor.</p>

<pre><code> class A {
   public: 
     A(B&amp; b); 
  }
</code></pre>

<p>And I have a class SubB which is a child class of B:</p>

<pre><code>class SubB : public B {
    //omitted...
 }
</code></pre>

<p>In my code, I create a SubB and pass it to A:</p>

<pre><code>   SubB subB; 
   A a(subB);
</code></pre>

<p>But I get this compile Error:</p>

<p>error: ‘B’ is an inaccessible base of ‘SubB’</p>

<p>Can I pass a reference of SubB as B?</p>

<p>Thank you.</p>
