title: Usage of union inside a class
body: <p>I saw some code as follows:</p>
  
  <pre><code>class A 
  {
  private:
      union {
          B *rep;
          A *next;
      }; // no variables of this anonymous defined!
  
      void func()
      {
          A *p = new A;
  
          p-&gt;next = NULL; // why p has a member variable of 'next'?
      }
  };
  </code></pre>
  
  <p>I have compiled the above code with VS2010 without any error.
  Here is the question,</p>
  
  <p>why p has member variable 'next'?</p>
  
  <pre><code>    union {
          B *rep;
          A *next;
      };
  </code></pre>
  
  <p>As far as I know, this is an anonymous union without even defining a variable. How can we access the member variables inside this union like that?</p>