Suppress delete-non-virtual-dtor warning when using a protected non-virtual destructor

后端 未结 2 1813
面向向阳花
面向向阳花 2021-01-18 01:17

I have a pure abstract interface class, and a derived class which implements the interface.

struct Foo
{
    virtual void doStuff() = 0;
};

struct Bar : Foo         


        
2条回答
  •  佛祖请我去吃肉
    2021-01-18 01:45

    Marking the class final remove the warning.

    struct Bar final : Foo
    {
        void doStuff() override { }
    };
    
    int main()
    {
        Bar* f = new Bar;
        f->doStuff();
        delete f;
    }
    

    Demo

提交回复
热议问题