How to delete an object of a polymorphic class type that has no virtual destructor

后端 未结 6 1192
清酒与你
清酒与你 2021-02-07 09:37

I am getting the following error when I try to compile some code from a Third-party SDK.

*Description    Resource    Path    Location    Type
deleting object of          


        
6条回答
  •  梦毁少年i
    2021-02-07 10:05

    Bad news, I am afraid. You should not use that class as a base class. Too many constraints and pitfalls. You might get away with it, but why risk it? File a bug report with the library vendor.

    If you do not need polymorphic pointers, include an object of that type in your class, and delegate the member functions you wanted to inherit.

    class my_class {
    private:
        evil_class evil;
    public:
        virtual ~my_class() {/* stuff */}
        virtual int member() { return evil.member(); }
    };
    

提交回复
热议问题