#include <iostream>
class a{
public:
a(){};
virtual ~a(){
std::cout << "del class a";
}
};
class b: public a{
public:
~b(){
std::cout << "del class b";
}
};
int main(){
a *pa;
pa = new b;
delete pa;
}
Hi, I'm fairly new to C++. Looking at the code example above, class b
does not have a virtual destructor, but when the program executes, the output is
del class b
then del class a
.
I'm wondering why that's the case, as I have not created a virtual destructor in class b
. Does that mean by declaring the base destructor virtual, the "virtualness" of the derived class is implicit?
Thanks.