title: Usage of Union in OOP
body: <p>Unions can be used as a type just like a class and structure(with some restrictions).It can have member functions. It can be used as an OOP construct.               </p>
  
  <p>As I understand unions were just imported in to C++ to maintain backward compatibility with C.<br>
  In all these years of programming I have never used an union like I would use an class or a structure as an OOP construct.     </p>
  
  <p>Is there any practical usage of Union as an OOP construct(not just as an data type) or it is just some vestigial part of the language that is never useful?</p>
  
  <hr>
  
  <p><strong>EDIT:</strong><br>
  The standard definitely allows union to act as an OOP construct. It allows for member functions in unions. Following code compiles and works and is standard compliant:    </p>
  
  <pre><code>union A
  {
      int a;
      int k;
  
      void doSomething(){}
  
  };
  
  int main()
  {
      A obj;
      int i = obj.a;
      obj.doSomething();
      return 0;
  }
  </code></pre>
  
  <p>Why does the standard allow member functions in an union if it is not supposed to act as an OOP construct?<br>
  Please post answers with specific reasoning and please refrain from posting an answer <em>I don't think so</em>, without a good reasoning of <em>why?</em></p>