2

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.

Ryan Haining
  • 35,360
  • 15
  • 114
  • 174
  • [the answer](http://stackoverflow.com/questions/13576055/how-is-default-different-from-for-default-constructor-and-destructor/13576544#13576544) – Ryan Haining Dec 10 '15 at 02:20

1 Answers1

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.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982