The person above made it clearer. Default will ask the compiler to add a {} for you. If your class holds some resources, the virtual destructor should not be empty, needs to do some cleanup work. For example:
If A is used as a parent class, then its destructor should be declared as virtual as much as possible to avoid the following situations:
class B : public A {
public:
//some declaration
virtual ~B() {}
};
//假使你获得了或者创建了一个A*类型的指向一个B*对象
{
A* a = new B();
delete a;//如果A的构造函数不是virtual,那么这个时候
//就是一个未定义行为,B的析构函数多半不会调用
//导致可能的资源/内存泄漏。
}
=default is not empty, but the default behavior is used, or the destructor of the member is called. This is not essentially different from writing {} directly.
The person above made it clearer. Default will ask the compiler to add a {} for you.
If your class holds some resources, the virtual destructor should not be empty,
needs to do some cleanup work. For example:
If A is used as a parent class, then its destructor should be declared as virtual as much as possible to avoid
the following situations:
No, you have explicitly defined the default destructor as your destructor. If you want to customize it, it will not be default
=default
is not empty, but the default behavior is used, or the destructor of the member is called. This is not essentially different from writing {} directly.