mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2025-12-17 20:54:41 +03:00
Closes #1748
This commit is contained in:
@@ -4669,21 +4669,16 @@ If you don't want a generated default function, suppress it with `=delete`.
|
||||
##### Example, good
|
||||
|
||||
When a destructor needs to be declared just to make it `virtual`, it can be
|
||||
defined as defaulted. To avoid suppressing the implicit move operations
|
||||
they must also be declared, and then to avoid the class becoming move-only
|
||||
(and not copyable) the copy operations must be declared:
|
||||
defined as defaulted.
|
||||
|
||||
class AbstractBase {
|
||||
public:
|
||||
virtual ~AbstractBase() = default;
|
||||
AbstractBase(const AbstractBase&) = default;
|
||||
AbstractBase& operator=(const AbstractBase&) = default;
|
||||
AbstractBase(AbstractBase&&) = default;
|
||||
AbstractBase& operator=(AbstractBase&&) = default;
|
||||
// ...
|
||||
};
|
||||
|
||||
Alternatively to prevent slicing as per [C.67](#Rc-copy-virtual),
|
||||
the copy and move operations can all be deleted:
|
||||
To prevent slicing as per [C.67](#Rc-copy-virtual),
|
||||
`=delete` the copy and move operations and add a `clone`:
|
||||
|
||||
class ClonableBase {
|
||||
public:
|
||||
@@ -4693,6 +4688,7 @@ the copy and move operations can all be deleted:
|
||||
ClonableBase& operator=(const ClonableBase&) = delete;
|
||||
ClonableBase(ClonableBase&&) = delete;
|
||||
ClonableBase& operator=(ClonableBase&&) = delete;
|
||||
// ... other constructors and functions ...
|
||||
};
|
||||
|
||||
Defining only the move operations or only the copy operations would have the
|
||||
|
||||
Reference in New Issue
Block a user