Is there a difference between a virtual destructor = default and an empty body?

A virtual destructor that does nothing

virtual ~ClassName() {}

Since C ++ 11, we can alternatively say :

virtual ~ClassName() = default;

Is there a difference between the two?

+4
source share
1 answer

The main difference is that there are rules for default functions that determine under what circumstances they are deleted (see ISO C ++ 14 ( N4296) 8.4, 12.1, 12.4, 12.8)

8.4.2.5: Explicit default functions and implicitly declared functions are collectively called default functions, and the implementation must contain implicit definitions for them (12.1, 12.4, 12.8), which may mean their removal.

:.

12.4.5: X , : (5.1) - X , , (5.2) - M ( ), M , , (5.3) - , , - ,

, default delete, {} .

+4

Source: https://habr.com/ru/post/1680636/


All Articles