class has virtual functions and accessible non-virtual destructor
This happens because your base class A
does not have a virtual destructor. For instance, if you had this code:
int main()
{
A* a = new B;
delete a;
}
Then the delete a
call would not be able to call B
's destructor because A
's isn't virtual. (It would leak all of B
's resources.) You can read more about virtual destructors here.
Add a virtual destructor to your base class and you should be fine.
class A
{
public:
virtual void somefunction() = 0;
virtual ~A() = default;
}
Give class A:
virtual ~A() { }
That way, derived classes such as B will still have their custom destructor called if you delete
them via an A*
.