ivanmejiarocha / micro-service

sample micro-service in C++
MIT License
263 stars 129 forks source link

non-virtual dtors in classes having virtual methods #16

Open user4223 opened 5 years ago

user4223 commented 5 years ago

...maybe this is not a problem in this concrete example, but when someone is deriving code from it and is extending it, it might lead to leaks when dtors of derived classes are not called properly (Item 7 in Scott Meyers Effective C++). See cfx::Controller and cfx::BasicController.

kadko commented 4 years ago

In order to fix the memory leak, one should define a virtual destructor

struct Base
{
    virtual ~Base() {}
    int myInt;
};