You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
serhij.zolotukhin edited this page Sep 27, 2026
·
3 revisions
dynamic typing
C++ is a statically typed language, meaning variable types are checked at compile time,
but you can simulate dynamic typing
(storing different types in the same variable at runtime)
using std::variant (introduced in C++17)
A variant is a data type introduced in C++ 17 that can hold values of different types, much like a union in C.
At its core, std::variant is a union of types.
It can store one value at a time from a predefined set of types.
Unlike a traditional union, std::variant keeps track of its active type, ensuring that you access the correct value.