3 ms·
From the article: """ Here be dragons, though, since we must always remember to: * Update tag whenever assigning a new value. * Only retrieve the correct ty
by humanrebar 9y ago
From the article:
"""
Here be dragons, though, since we must always remember to:
* Update tag whenever assigning a new value.
* Only retrieve the correct type from the union (according to tag).
* Call constructors and destructors at appropriate times for all non-trivial types. (string is the only one here, but you could imagine similar scenarios with others.)
"""
...the last paragraph is the part that will almost surely trip a C++ newcomer up if they tried this out. The first to are (valid in my experience) complaints about maintenance mistakes that result in compiling programs but runtime errors.