Menu

Destructor in base class: public and virtual or protected and non virtual

2020-03-03
2020-03-04
  • Lionel Gimbert

    Lionel Gimbert - 2020-03-03

    Based on Cpp Core Guidelines, the good practice for base classes is to have either a public virtual destructor or a proteted non-virtual destructor (ref: https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rc-dtor-virtual).

    If cppcheck (current head of master) is run with "inconclusive", if there is a virtual method in the base class a protected non virtual destructor will trigger a virtualDestructor error.

    From what I seen, changing this would just require to check destructor access specifier in CheckClass::virtualDestructor().

     
  • Daniel Marjamäki

    From what I seen, changing this would just require to check destructor access specifier in CheckClass::virtualDestructor().

    Yeah it is probably a small tweak. Can you open a github pull request?

     
  • Lionel Gimbert

    Lionel Gimbert - 2020-03-04

    It will propably take some days before I have the time do do a proper pull request but there should be no problem.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.