CppPilot

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

  1. A move-only object is copied. std::unique_ptr, std::thread, and std::mutex cannot be copied: pass them by reference, or transfer them with std::move.
  2. A class that contains one is copied. A class with a unique_ptr member is move-only too: move it into containers (push_back(std::move(item)) or emplace_back), or define its copy yourself.
  3. A lambda that owns one is stored in std::function. std::function requires a copyable callable: use std::move_only_function in C++23, or a std::shared_ptr.
  4. A member makes assignment impossible. A const or 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.

Get CppPilot free Get started

Related errors: C2440. See all guides.