File: nonvirtual_destructor.cc

package info (click to toggle)
ignition-cmake 2.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,132 kB
  • sloc: xml: 35,671; python: 3,768; javascript: 2,308; sh: 172; ansic: 109; cpp: 64; makefile: 7
file content (30 lines) | stat: -rw-r--r-- 525 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

#include <string>

#include <ignition/utilities/SuppressWarning.hh>

class Base
{
  virtual std::string printStuff() = 0;
};

IGN_UTILS_WARN_IGNORE__NON_VIRTUAL_DESTRUCTOR
class Derived : public Base
{
  std::string stuff;
  std::string printStuff() override { return stuff; }
};
IGN_UTILS_WARN_RESUME__NON_VIRTUAL_DESTRUCTOR

Base *MakeDerived()
{
  return new Derived;
}

int main()
{
  Base *b = MakeDerived();
  IGN_UTILS_WARN_IGNORE__NON_VIRTUAL_DESTRUCTOR
  delete b;
  IGN_UTILS_WARN_RESUME__NON_VIRTUAL_DESTRUCTOR
}