LearnFrenzy
Sign in Take a free test

Smart Pointers · Smart Pointers MCQ · Question 2

Can a unique_ptr be copied? Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 2 Back to Exercise

What happens with auto b = a; when a is a std::unique_ptr?

  • A Both point to the object
  • B Compile error – unique_ptr is move-only; use std::move(a) Correct
  • C The object is copied
  • D a is deleted
Correct Answer: Option B

Moving transfers ownership and leaves a empty.

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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links