加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 如何删除没有虚拟析构函数的多态类类型的对象

发布时间:2020-12-16 06:00:28 所属栏目:百科 来源:网络整理
导读:当我尝试从第三方SDK编译一些代码时,我收到以下错误. *Description Resource Path Location Typedeleting object of polymorphic class type ‘Vendor_sys::VendorCode’ which has non-virtual destructor might cause undefined behaviour [-Werror=delete
当我尝试从第三方SDK编译一些代码时,我收到以下错误.
*Description    Resource    Path    Location    Type
deleting object of polymorphic class type ‘Vendor_sys::VendorCode’ which has non-virtual destructor might cause undefined behaviour [-Werror=delete-non-virtual-dtor]   PnServer.cpp    /PCounter   line 467    C/C++ Problem*

我不知道它是否可以满足这种条件,只有部分了解供应商的SDK,其中大部分重物在dll或库对象中完成.

我的构建环境是使用gpp的Eclipse Juno.

我在Google中搜索了错误消息,没有发现任何此错误的实例.

所以,如果我不能修改供应商代码的黑盒子部分,我的选择是什么?

这是在make过程中失败的代码:

delete pData->unit;

解决方法

坏消息,恐怕.你不应该使用该类作为基类.太多的限制和陷阱.你可能会放弃它,但为什么要冒险呢?向图书馆供应商提交错误报告.

如果您不需要多态指针,请在类中包含该类型的对象,并委托您要继承的成员函数.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读