I need to have several instances of a union as class variables, so how can I create a union instance in the heap? thank you
The same as creating any other object:
union MyUnion
{
   unsigned char charValue[5];
   unsigned int  intValue;
};
MyUnion *myUnion = new MyUnion;
Your union is now on the heap. Note that a union is the size of it's largest data member.
My C++ is a bit rusty, but:
   my_union_type *my_union = new my_union_type;
   ...
   delete my_union;
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With