MSVC build errors > C2280
C2280: attempting to reference a deleted function
error C2280: 'std::unique_ptr<Widget,std::default_delete<Widget>>::unique_ptr(const std::unique_ptr<Widget,std::default_delete<Widget>> &)': attempting to reference a deleted function
The code calls a function that is deleted, most often the copy constructor or the copy assignment of a type that can only be moved.
Causes and fixes
- A move-only object is copied.
std::unique_ptr,std::thread, andstd::mutexcannot be copied: pass them by reference, or transfer them withstd::move. - A class that contains one is copied. A class with a
unique_ptrmember is move-only too: move it into containers (push_back(std::move(item))oremplace_back), or define its copy yourself. - A lambda that owns one is stored in
std::function.std::functionrequires a copyable callable: usestd::move_only_functionin C++23, or astd::shared_ptr. - A member makes assignment impossible. A
constor reference member deletes the copy assignment: assign member by member, or store a pointer.
Fix C2280 with CppPilot
CppPilot reads the error, your code, and the project settings Visual Studio evaluates for the active configuration, then explains which of these causes applies. Choose Fix and the AI corrects it; CppPilot rebuilds the project and checks that the error is gone. Every change appears in Visual Studio for your approval.
Let the AI fix it in Visual Studio
CppPilot is a free extension that explains and fixes MSVC build errors with Codex, Claude, or CppPilot Cloud.
Related errors: C2440. See all guides.