默认虚拟设备 [英] default virtual d'tor

查看:117
本文介绍了默认虚拟设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们假设我有两个类:

Let us assume I have two classes:

class Base{};

class Derived: public Base{};

none has d'tor,在这种情况下,如果我声明关于变量:

none has d'tor, in this case if I declare about variables:

Base b;
Derived d;

我的编译器会为我生成,我的问题是,默认的 b和d 是否为虚拟?

my compiler will produce for me d'tors, my question is, the default d'tors of the b and d will be virtual or not?

推荐答案


我的问题是,b和d的对象将是虚拟的

my question is, the d'tors of the b and d will be virtual or not

t。如果你想要一个虚拟析构函数,你必须定义你自己的,即使它的实现与编译器提供的完全一样:

No, they won't. If you want a virtual destructor, you will have to define your own, even if its implementation is exactly the same as that which would be supplied by the compiler:

class Base {
  public:
    virtual ~Base() {}
};

这篇关于默认虚拟设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆