I never use unions in C++. Mostly because I typically work at a high enough leve...

@charette@mstdn.ca

I never use unions in C++. Mostly because I typically work at a high enough level that I don't need to worry about them.

Recently looked up the details, and other than the last one, was surprised to find out:

- Unions can have constructors, destructors, and methods.

- Unions can use public, private, protected, just like classes; they're public by default, like structs.

- Unions cannot be used as a base class, or have a base class.

- Unions cannot have virtual methods.

- And unsurprisingly, it is UB to read a member that was not the most recently assigned. #cpp