This correct code produces " ~B ~A" i.e. reverse construction sequence. But what if "virtual" removed?
I said it's undefined behavior, but what if we know it does do something? I correctly predicted " ~A". My bloomberg interviewer predicted " ~B" but failed my test.
class A{
public: virtual ~A(){ cout<<" ~ A"<<endl; }
};
class B: public A{
public: ~B(){ cout<<" ~ B "; }
};
int main(){
A * p = new B;
delete p;
cin.get();
}