C++ Compiler Error C2280 attempting to reference a deleted function in Visual Studio 2013 and 2015
C++ Compiler Error C2280 attempting to reference a deleted function in Visual Studio 2013 and 2015
From [class.copy]/7, emphasis mine:
If the class definition does not explicitly declare a copy constructor, a non-explicit one is declared implicitly.
If the class definition declares a move constructor or move assignment operator, the implicitly declared copy
constructor is defined as deleted; otherwise, it is defined as defaulted (8.4). The latter case is deprecated if
the class has a user-declared copy assignment operator or a user-declared destructor.
There is an equivalent section with similar wording for copy assignment in paragraph 18. So your class is really:
class A
{
public:
// explicit
A(){}
A(A &&){}
// implicit
A(const A&) = delete;
A& operator=(const A&) = delete;
};
which is why you cant copy-construct it. If you provide a move constructor/assignment, and you still want the class to be copyable, you will have to explicitly provide those special member functions:
A(const A&) = default;
A& operator=(const A&) = default;
You will also need to declare a move assignment operator. If you really have a need for these special functions, you will also probably need the destructor. See Rule of Five.
I had the same problem and it was due to a poorly defined member variable:
double const deltaBase = .001;
Putting this in will cause the copy constructor to be deleted. Get rid of the const and assign in the constructor.
C++ Compiler Error C2280 attempting to reference a deleted function in Visual Studio 2013 and 2015
I was stuck with this error even after defaulting the copy ctor. Turned out, one of my class member (rapidjsons Document object) was disallowing copy. Changed it to a reference, initialized via a *(new rapidjson::Document()) in the default ctors initializer list. Looks like all individual members should also be copyable in addition to the defaulted copy ctor.
Related posts on C++ :
- Can vector pop from front C++?
- What does Fin eof () do in C++?
- Can you pop from a vector C++?
- How do I find a value in a vector C++?
- How do you create a blank vector in C++?
- What is fixed in Setprecision C++?
- What is std :: Bad_alloc C++?
- Can you use Push_back in string C++?
- What is the use of climits in C++?