Everyone says that a destructor must be virtual when at least one of the class methods is virtual.
My questions are: is it right to say that the destructor must be virtual when using upstream?
class A {
public:
~A(){
cout << "Destructor in A" << endl;
}
};
class B: public A
{
public:
~B(){
cout << "Destructor in B" << endl;
}
};
int main()
{
A* a = new B;
cout << "Exiting main" << endl;
delete a;
}
I do not have any virtual functions in this code, but if I do not make my base destructor virtual, it will not call the destructor B. And yes, I know that it makes no sense to use ucpasting if I do not have virtual functions.
Thank.
source
share