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 唉。这么简单的东东。动手试一下不就是了。当然,这个问题是应该脱口就能答出来的 |
|