Object lifetime
This lesson discusses how std::variant handles object lifetime.
We'll cover the following
std::variant
and Object Lifetime
When you use union, you need to manage the internal state: call constructors or destructors. This is error-prone, and it’s easy to shoot yourself in the foot. But std::variant
handles object lifetime as you expect. That means that if it’s about to change the currently stored type, then a destructor of the underlying type is called.​
Get hands-on with 1400+ tech skills courses.