Let's say you have:
class Base
{
public:
virtual ~Base();
private:
int someTrivialValue;
}
class Derived : public Base
{
}
- I believe creating the virtual destructor in
Base
is required. - Since a destructor is explicity declared, a default ctor and copy/move should also be explicity defined as per the Rule of 5, even if they only contain primitive data types or even user-defined objects allocated on the stack.
- The default ctor, copy and move operations, they have to be explicitly defined in both the base and derived classes.
- It is ok to use
= default
for the default ctor and copy - I am on VS 2013 and it does not allow using
=default
for move operations. So this means I have to manually writefield = std::move(rhs.field)
for every single variable in each class.
Please correct any of my above statements if they are incorrect.
Aucun commentaire:
Enregistrer un commentaire