title: Union of const/non-const Object Pointers
body: <p>Consider the sample code below:</p>
  
  <pre><code>class A
  {
  public:
  
      A() : n(0) {}
  
      int n;
  };
  
  class B
  {
  public:
  
      B(A* a) : mA(a) { }
      B(const A* a) : mConstA(a) { }
  
      union {
          A* mA;
          const A* mConstA;
      };
  };
  
  int main()
  {
      A a;
      B b1(&amp;a);
      B b2(const_cast&lt;const A*&gt;(&amp;a));
  
      return 0;
  }
  </code></pre>
  
  <p>At construction, <code>b1</code> would have a mutable pointer to <code>a</code>, while <code>b2</code> would have an immutable pointer to <code>a</code>. In this scenario, <code>b1.mA</code> equals <code>b2.mConstA</code>, and <code>b1.mConstA</code> equals <code>b2.mA</code>.</p>
  
  <p>Are these equalities always true when you have a union of <code>const</code> and non-<code>const</code> object pointers?</p>
  
  <p>Similarly, the code below compiles/runs fine:</p>
  
  <pre><code>int main()
  {
      const A a;
      B b(&amp;a);
      b.mA-&gt;n = 3; // Blasphemy!!!
  
      return 0;
  }
  </code></pre>
  
  <p>But is it guaranteed for <code>b.mA</code> to always be equal to <code>b.mConstA</code>?</p>