I'm wondering what the differences are between a Boost Variant and a union
data-type in c/c++. I know that a union
data-type takes up the same memory location and the largest data type in the region of memory occupies the total amount of memory used e.g.
union space {
char CHAR;
float FLOAT;
int INTEGER;
}S;
should occupy 4 bytes of memory since int
and float
are the largest and equal size. Are there similarities and differences in other ways between Boost Variant and union
data types?
I also know that a Boost Variant can take any data type and it allows data type "polymorphism" (correct me if I'm misusing a OOP topic word). Is a union data type therefore a type of polymorphism also?