What are the semantics of =delete? -- StackOverflow

The question, rephrased: Does =delete mean "make the compiler skip this function and keep looking," or "make this function unusable and make the caller fix their code" -- and why?

What's the exact semantics of a deleted function in C++11?

struct A
{
    A();

    A(const A&);
    A& operator =(const A&);

    A(A&&) = delete;
    A& operator =(A&&) = delete;
};

struct B
{
    B();

    B(const B&);
    B& operator =(const B&);   
};

int main()
{
    A a;
    a = A(); // error C2280

    B b;
    b = B(); // OK
}

My compiler is VC++ 2013 RC.

error C2280: 'A &A::operator =(A &&)' : attempting to reference a deleted function

I just wonder why the compiler doesn't try A& operator =(const A&); when A& operator =(A&&) is deleted?

Is this behavior defined by the C++ standard?

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.