Question 19
Back to Exercise
When is std::variant with std::visit a better choice than a virtual class hierarchy?
- A When new types will be added by other libraries
- B When the set of types is closed and known in advance, values are stored directly, and new operations are added often Correct
- C Never
- D Only for numbers
Correct Answer: Option B
Inheritance is open to new types; variant is open to new operations (visitors). Each makes the other kind of extension harder.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!