Multiple ChoiceHard 45s
enable_shared_from_this caveat
Why does calling `shared_from_this()` inside a constructor throw `std::bad_weak_ptr`?
Options
- 1The control block's weak reference is only initialized once the shared_ptr fully owns the object, which hasn't happened during construction.
- 2Because the object is stack-allocated by definition while its constructor runs, so no owner can exist yet.
- 3Because make_shared has not run yet even though the constructor is executing, leaving the weak count unset.
- 4It does not throw at all; it returns an empty shared_ptr, and only a later use of that returned pointer throws.
Think you can answer under pressure?
Get matched and answer live questions in 3-minute 1v1 battles. Elo ranking, badge tiers and bragging rights on the line.