title: How to access class member from inner union in C++
body: <p>I've a small problem:</p>
  
  <pre><code>class A {
       public:
       enum _type {TYPE1=0,TYPE2,TYPE3} type;
       union U{
           struct _type1 {
               //somme data
           } type1;
  
           struct _type2 {
              //some other data
              std::vector&lt;int&gt; v;
           } type2;
  
           struct _type3 {
              // some other data
           } type3;
  
           U() { //constuctor
              switch(type){ // access to A::type =&gt; not accept at compile time
                 case TYPE1 : /*init type1*/ break;
                 case TYPE2 : /* init type2 */; new(&amp;v) std::vector&lt;int&gt;; break;
                 case TYPE3 : /* init type3 */ break;
                 default : break;
           }
  
           ~U(){ //I need it to delete placement new
               switch(type)
               {
                    //same probleme
                    case TYPE2: v.~vector&lt;int&gt;(); break;
                    default : break;
               }
          }
       }
   };
  </code></pre>
  
  <p>the error:</p>
  
  <blockquote>
    <p>invalid use of non-static data member</p>
  </blockquote>
  
  <p>As you can see, I just need to access in the union constructor to a data of the main class.
  I need this to deal with "unrestricted union" (data member of the union are object in reality) so I really need to use union and not a other class.</p>
  
  <p>Edit:
  Finaly, I find a solution for this case:</p>
  
  <pre><code>class A {
      public:
          A(int t); // &lt;= add U() code here
          ~A(); // &lt;= add ~U()  code here
      union {
          //same union data
      }; //move to anonymous union
  };
  </code></pre>