lundi 1 octobre 2018

When would I default (as opposed to delete) copy and move operations in a base class

In the CppCoreGuidelines item C.21, this example shows the copy/move special functions being declared =default in an AbstractBase class. It then goes on to say

Alternatively to prevent slicing as per C.67, the copy and move operations can all be deleted

and provides a second example with the functions declared with =delete.

If I have a class that is intended to be a base class in an inheritance hierarchy, should I always use the second example and delete the copy/move special functions to prevent slicing? Why would I use =default instead, if it opens the class up to errors?

Aucun commentaire:

Enregistrer un commentaire