Why does the cast operator to a private base not get used? : <p>In this code assigning to b1 works, but it won't allow assigning to b2 (with or without the static cast). I was actually trying to solve the opposite problem, public inheritance but not implicitly converting to the base. However the cast operator never seems to be used. Why is this?</p>

<pre><code>struct B {};    

struct D1 : private B {
    operator B&amp;() {return *this;}
    B&amp; getB() {return *this;}
};

struct D2 : public B {
    explicit operator B&amp;() {return *this;}
};

struct D3 : public B {
    operator B&amp;() = delete;
};

void funB(B&amp; b){}

int main () {
  D1 d1;
  funB(d1.getB()); // works
  // funB(d1); // fails to compile with 'inaccessible base class
  D2 d2;
  funB(d2); // works
  D3 d3;
  funB(d3); // works 
  return 0;
}
</code></pre>
