jweinst1
8/24/2017 - 9:34 PM

example union object cpp

example union object cpp

#include <iostream>

//example about union struct links

//basic data object
struct Data
{
  enum
  {
    Int,
    Bool,
    Char,
    Pnt
  } type;
  
  union
  {
    int i;
    char c;
    bool b;
    Data* p;
  };
  
};

int main() {
  //sample init
  Data a = {Data::Bool};
  std::cout <<  a.type << "\n";
}