Inspired by the post Why does destructor disable generation of implicit move methods?, I was wondering if the same is true for the default virtual destructor, e.g.
class WidgetBase // Base class of all widgets
{
public:
virtual ~WidgetBase() = default;
// ...
};
As the class is intended to be a base class of a widget hierarchy I have to define its destructor virtual to avoid memory leaks and undefined behavior when working with base class pointers. On the other hand I don't want to prevent the compiler from automatically generating move operations.
Does a default virtual destructor prevent compiler-generated move operations?
Yes, declaring any destructor will prevent the implicit-declaration of the move constructor.
Declaring the destructor and defining it as
default
counts as user-declared.You'll need to declare the move constructor and define it as
default
yourself:Note that this will in turn define the copy constructor as
delete
, so you'll need todefault
that one too:The rules for copy and move assignment operators are pretty similar as well, so you'll have to
default
them if you want them.