title: How can subclass pointers strictly equal parent class pointers?
body: <p>I was writing an operator== between two kinds of smart pointer and thought I should run a quick sanity check. I'm suprised by the result...</p>
  
  <p>In the snippet below how is it that all variants of f and b end up with the same value?</p>
  
  <pre><code>struct Foo {
      int x;
  };
  
  struct Bar : public Foo {
      int y;
  };
  
  #include &lt;iostream&gt;
  
  int main ()
  {
      Bar bar;
  
      Foo * f = &amp;bar;
      Bar * b = &amp;bar;
      std :: cout &lt;&lt; f &lt;&lt; " " &lt;&lt; b &lt;&lt; " " &lt;&lt; (f == b) &lt;&lt; "\n";
  
      void * fv = f;
      void * bv = b;
      std :: cout &lt;&lt; fv &lt;&lt; " " &lt;&lt; bv &lt;&lt; " " &lt;&lt; (fv == bv) &lt;&lt; "\n";
  
      int fi = reinterpret_cast &lt;int&gt; (f);
      int bi = reinterpret_cast &lt;int&gt; (b);
      std :: cout &lt;&lt; fi &lt;&lt; " " &lt;&lt; bi &lt;&lt; " " &lt;&lt; (fi == bi) &lt;&lt; "\n";
  }
  </code></pre>