title: Accessing string in a union inside a struct in C++14
body: <p>Can anyone please explain how to use and access string in a union inside a structure with the help of unrestricted union?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  typedef struct {
              int height;
              int width;
          } Page;
  
  typedef struct {
              int test;
              union {
                  Page page;
                  int intVar;
                  string  stringVar;
              } VarUnion;
          } VariableDataStruct;
  
  int main()
  {
      VariableDataStruct structeg;
      structeg.VarUnion.stringVar = "Hello";
      return 0;
  }
  </code></pre>
  
  <p>Currently getting following errors on compilation:</p>
  
  <p>unionstring2.cc: In function ‘int main()’:
  unionstring2.cc:22:24: error: use of deleted function ‘VariableDataStruct::VariableDataStruct()’
       VariableDataStruct structeg;
                          ^
  unionstring2.cc:11:16: note: ‘VariableDataStruct::VariableDataStruct()’ is implicitly deleted because the default definition would be ill-formed:
   typedef struct {
                  ^
  unionstring2.cc:11:16: error: use of deleted function ‘VariableDataStruct::::()’
  unionstring2.cc:13:19: note: ‘VariableDataStruct::::()’ is implicitly deleted because the default definition would be ill-formed:
               union {
                     ^
  unionstring2.cc:16:11: error: union member ‘VariableDataStruct::::stringVar’ with non-trivial ‘std::basic_string&lt;_CharT, _Traits, _Alloc>::basic_string() [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator]’
     string  stringVar;
             ^
  unionstring2.cc:11:16: error: use of deleted function ‘VariableDataStruct::::~()’
   typedef struct {
                  ^
  unionstring2.cc:13:19: note: ‘VariableDataStruct::::~()’ is implicitly deleted because the default definition would be ill-formed:
               union {
                     ^
  unionstring2.cc:16:11: error: union member ‘VariableDataStruct::::stringVar’ with non-trivial ‘std::basic_string&lt;_CharT, _Traits, _Alloc>::~basic_string() [with _CharT = char; _Traits = std::char_traits; _Alloc = std::allocator]’
     string  stringVar;
             ^
  unionstring2.cc:22:24: error: use of deleted function ‘VariableDataStruct::~VariableDataStruct()’
       VariableDataStruct structeg;
                          ^
  unionstring2.cc:18:11: note: ‘VariableDataStruct::~VariableDataStruct()’ is implicitly deleted because the default definition would be ill-formed:
           } VariableDataStruct;
             ^
  unionstring2.cc:18:11: error: use of deleted function ‘VariableDataStruct::::~()’</p>