What does Delete do in front of the constructor?

3

What does this *delete mean in front of the constructor?

Grap& operator=(const Grab &g) = delete;
    
asked by anonymous 08.11.2016 / 15:14

1 answer

2

Note that this is an assignment operator and not a constructor. And it's a matter of point of view, but for me the keyword delete behind the operator statement.

It is invalidating this operation. Every type in C ++ has the assignment operator created automatically by the compiler if none is provided. When your type can not allow assignments to be made with it, this is the way to prevent the compiler from creating the operator for you.

You can do the same with the copy operator.

Only available from C ++ 11.

    
08.11.2016 / 15:34