3

I'm trying do declare pure virtual destructor, in VS2019 I'm writing like that:

    virtual ~A() = 0 {};

and it's fine, but in Clion don't accept that I'm getting the following message:

pure-specifier on function-definition virtual ~A() = 0{ };

and it forces me to write a different implementation for the function (not that it to much trouble but id like to know why is that)

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
yaodav
  • 1,126
  • 12
  • 34
  • I just was about to edit :D – user1810087 Sep 25 '19 at 11:26
  • Pure specifier and definition at the same time is not valid indeed. It would probably be a good idea to fill a bug report. – user7860670 Sep 25 '19 at 11:27
  • _in VS2019 I'm writing like that: `virtual ~A() = 0 {};` and it's fine_ That might be a native extension of MS (and not the first one I recognized). – Scheff's Cat Sep 25 '19 at 11:34
  • In the declaration, `virtual ~A() = 0;` and provide an implementation after the declaration `inline A::~A() = default;` (because it is a destructor, it still needs to be provided). If the implementation is in the .cpp file, omit the `inline`. If the destructor needs to do something other than `default` provide the destructor behavior as needed. – Eljay Sep 25 '19 at 11:40

1 Answers1

5

From the C++ 20 (11.6.3 Abstract classes)

  1. ...[Note: A function declaration cannot provide both a pure-specifier and a definition — end note] [Example:
struct C {
  virtual void f() = 0 { }; // ill-formed
};

— end example]

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335