T
tuvok
Is it correct that the virtual dtor of base gets called implicitly?
Here's some code to demonstrate what I mean:
Class B has a virtual destructor, so has class D which
is derived from B. Deleting D calls the dtor of D and
then the dtor of B.
I was thinking that this would be true only for non-virtual dtor case,
but I wouldn't have expected it happen for a virtual dtor.
For a class with a virtual dtor I would have expected that only
the dtor of D would be called when D gets deleted.
What's correct? Is maybe my compiler buggy?
class B
{
public:
B() {}
virtual ~B() { std::cout << "~B\n"; }
};
class D : public B
{
public:
D() {}
virtual ~D() { std::cout << "~D\n"; }
};
void virtual_dtor_tester()
{
B b;
D d;
}
/* output:
~D
~B
~B
*/
Here's some code to demonstrate what I mean:
Class B has a virtual destructor, so has class D which
is derived from B. Deleting D calls the dtor of D and
then the dtor of B.
I was thinking that this would be true only for non-virtual dtor case,
but I wouldn't have expected it happen for a virtual dtor.
For a class with a virtual dtor I would have expected that only
the dtor of D would be called when D gets deleted.
What's correct? Is maybe my compiler buggy?
class B
{
public:
B() {}
virtual ~B() { std::cout << "~B\n"; }
};
class D : public B
{
public:
D() {}
virtual ~D() { std::cout << "~D\n"; }
};
void virtual_dtor_tester()
{
B b;
D d;
}
/* output:
~D
~B
~B
*/