Home » Programming Languages » C++ Programs » Fixed: has virtual functions but non-virtual destructor

Fixed: has virtual functions but non-virtual destructor

If we have a C++ Class “MyLynxbee” declared in header file mylynxbee.h as below,

class MyLynxbee
{
public:
    MyLynxbee();
    virtual int helloworld();
}

and if we try to compile this code, we may get compilation error as,

error: 'MyLynxbee' has virtual functions but non-virtual destructor [-Werror,-Wnon-virtual-dtor]

Solution :

Make sure you update the header and add virtual destructor as,

class MyLynxbee
{
public:
    MyLynxbee();
    virtual int helloworld();
    virtual ~MyLynxbee();
}

And also add corresponding descructor in C++ class code as,

MyLynxbee::~MyLynxbee()
{
}

Now, if you compile the same code. You will not see this error.

Manually Remove Broken VMs in Hyper...
Manually Remove Broken VMs in Hyper-V Manager [Fix]

Leave a Comment

Sign up to our newsletter!