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

后端 未结 6 1172
清酒与你
清酒与你 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条回答
  •  感情败类
    2021-02-07 10:24

    Well it's a bug in the third-party SDK. Any class that is used as a base class should have a virtual destructor. Otherwise, when you delete a pointer to the base of a derived class instance, the derived class's destructor won't be called.

    One way around it is to not delete pointers to the base. Instead, use dynamic_cast to get a pointer to the derived class (this might be inconvenient if there are many classes derived from that base).

提交回复
热议问题