Pure virtual destructor with default keyword

Is it possible to declare a destructor as pure virtual and use the default keyword? For example, I cannot make the code this way:

class MyClass
{
public:
  // Is there a way to combine pure virtual and default?
  virtual ~ MyClass() = 0,default;
};

      

You can, of course, later:

MyClass::~ MyClass() = default;

      

Also, if the destructor is not purely virtual, the default keyword works when it follows the declaration.

+3


source to share


3 answers


Not.

You will need to write a separate definition default

there as well, as you showed.



Having a pure-qualifier eliminates having a definition in the same place, even if the definition is simple = default

.

+7


source


No, It is Immpossible.

By declaring a member function with a qualifier = default

, you provide the function definition.

From the working draft of the C ++ 14 standard (N3936):



ยง 10.4 Note. A function declaration cannot provide both a specifier and a definition

https://github.com/cplusplus/draft/raw/b7b8ed08ba4c111ad03e13e8524a1b746cb74ec6/papers/N3936.pdf

+2


source


This question does not seem to be a starter since you can only have one destructor . Why do you need to add a specifier default

?

-4


source







All Articles