Question 20
Back to Exercise
What happens with std::any a = 5; std::any_cast<double>(a);?
- A It returns 5.0
- B It throws std::bad_any_cast – the stored type is int, and any_cast requires the exact type Correct
- C Compile error
- D Undefined behaviour
Correct Answer: Option B
The pointer form any_cast<double>(&a) returns nullptr instead of throwing.
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!