What are unions in C++?

In C++17 and later, the std::variant class is a type-safe alternative for a union. A union is a user-defined type in which all members share the same memory location . This definition means that at any given time, a union can contain no more than one object from its list of members.

Read more