Difference between virtual ~T(){} and virtual ~T() = default;

时间:2015-12-10 01:51:53

标签: c++ c++11

When writing a virtual destructor, is there any functional or outwardly-discernible difference between having

virtual ~T() = default;

over

virtual ~T() {}

They both seem to have the same affect on anything from type_traits I could think to test with.

1 个答案:

答案 0 :(得分:2)

They are effectively the same. While there is a difference with non-virtual destructors, once you stick virtual in there, it cannot be trivial anymore.

This is not the only time that = default leads to the generation of a non-trivial special member function. For example, if you have a member that has a non-trivial destructor, then using = default will not cause the creation of a trivial destructor for the containing type, even with a non-virtual destructor.

You should use = default anyway, just to make it clear what your intentions are.

相关问题