1

I stumbled upon destructor that is both set as pure virtual but also has brackets behind it for an implementation. I am confused. What does it mean and why is it written like that?

virtual ~MyClass() = 0 {}
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778
  • you code doesn't compile because you can't provide an inline implementation to a pure virtual method. But you can out of the class. Other than that see the dupe. – bolov May 22 '20 at 13:32
  • @bolov The code compiles just fine, I just wasn't sure what it meant. Even with the linked dupe, I am still not sure why is it there. – Tomáš Zato May 22 '20 at 13:33
  • what compiler with which flags? gcc and clang reject the code https://godbolt.org/z/eEbz8_ – bolov May 22 '20 at 13:38
  • 1
    You will usually this strategy used when you want `MyClass` to be abstract but have no `virtual` members that can be pure virtual. In that case you can always make the destructor pure virtual. The derived type never has to (and in fact can't) `override` the destructor, but `MyClass` is still abstract. But you still need to provide a destructor implementation or `MyClass` and any derived type won't be destructible and functionally unusable. – François Andrieux May 22 '20 at 13:44

0 Answers0