What ownership rule does std::unique_ptr enforce in C++?
Correct answer
A. Exactly one owner, with ownership transferred by move
14 views
A. Exactly one owner, with ownership transferred by move
14 views
A unique_ptr models exclusive ownership: copying is deleted, so the pointer must be transferred with std::move, and the deleter runs when that single owner is destroyed. shared_ptr, by contrast, keeps a reference count so several owners can share the same object. The unique form has no counting overhead and is the default choice when ownership is not genuinely shared.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is A? Ask here and get an explanation.