Deleted functions

In C++11 is it possible to remove a function from a class by using the delete specifier. If you try to use a deleted function will give a compiler error.

As an example, the following class is made non-movable by making it impossible to call the move operator and move constructor:

We can also stop anyone from creating instances of a class on the free store (heap)  by deleting the new operator:

Or more compact by using a template

To stop users from calling a method with specific parameters, delete the functions with the not allowed parameters:

 

Facebookgoogle_pluslinkedinmail