由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - C++ virtrual destructor
相关主题
各位总结一下区别:virtual function and virtual destructor?C/C++ Questions
C++ Q36: derivation specification (B8_9)C++ Q29: extern and const together
c++ class default functions?C++ Q42: (C22)
一道brianbench C++题C++ 一问?
发个面经吧C++ online Test 又一题
bloomberg offer附面经C++ Q83: 这个const_cast什么意思?
c++ inline问题问个C++模板定义的问题
彭博电面面经leetcode OJ 不能使用exception?
相关话题的讨论汇总
话题: virtual话题: destructor话题: class话题: virtrual话题: c++
进入JobHunting版参与讨论
1 (共1页)
d**f
发帖数: 264
1
Class A
{
A(){};
virtual ~A(){};
}
Class B : public A
{
B(){};
~B(){};
};
是不是~B() 有无virtual是一样的?
e******0
发帖数: 211
2
不行, base 定义了 析构函数是virtual,
derived必须也定义析构函数是virtual

【在 d**f 的大作中提到】
: Class A
: {
: A(){};
: virtual ~A(){};
: }
: Class B : public A
: {
: B(){};
: ~B(){};
: };

c****o
发帖数: 1280
3
Note: in a derived class, if your base class has a virtual destructor, your
own destructor is automatically virtual. You might need an explicit
destructor for other reasons, but there's no need to redeclare a destructor
simply to make sure it is virtual. No matter whether you declare it with the
virtual keyword, declare it without the virtual keyword, or don't declare
it at all, it's still virtual.

【在 e******0 的大作中提到】
: 不行, base 定义了 析构函数是virtual,
: derived必须也定义析构函数是virtual

c********s
发帖数: 1024
4
can't agree more...

your
destructor
the
declare

【在 c****o 的大作中提到】
: Note: in a derived class, if your base class has a virtual destructor, your
: own destructor is automatically virtual. You might need an explicit
: destructor for other reasons, but there's no need to redeclare a destructor
: simply to make sure it is virtual. No matter whether you declare it with the
: virtual keyword, declare it without the virtual keyword, or don't declare
: it at all, it's still virtual.

h******u
发帖数: 104
5
唉。这么简单的东东。动手试一下不就是了。当然,这个问题是应该脱口就能答出来的
1 (共1页)
进入JobHunting版参与讨论
相关主题
leetcode OJ 不能使用exception?发个面经吧
问个C++的问题bloomberg offer附面经
List x; and List x();c++ inline问题
被三哥黑了彭博电面面经
各位总结一下区别:virtual function and virtual destructor?C/C++ Questions
C++ Q36: derivation specification (B8_9)C++ Q29: extern and const together
c++ class default functions?C++ Q42: (C22)
一道brianbench C++题C++ 一问?
相关话题的讨论汇总
话题: virtual话题: destructor话题: class话题: virtrual话题: c++