Suppose we have a (toy) C++ class such as the following:
class Foo {
public:
Foo();
private:
int t;
};
Since no destructor is defined, a C++ compiler should create one automatically for class Foo
. If the destructor does not need to clean up any dynamically allocated memory (that is, we could reasonably rely on the destructor the compiler gives us), will defining an empty destructor, ie.
Foo::~Foo() { }
do the same thing as the compiler-generated one? What about an empty constructor -- that is, Foo::Foo() { }
?
If there are differences, where do they exist? If not, is one method preferred over the other?
I'd say best to put the empty declaration, it tells any future maintainers that it wasn't an oversight, and you really did mean to use the default one.