mom*_*arX 6 c++ virtual destructor
为什么派生的析构函数没有用 clang++ 10 调用,它在 g++ 9 中按预期工作?为什么我得到
BC
DC
BD
Run Code Online (Sandbox Code Playgroud)
代替
BC
DC
DD
BD
Run Code Online (Sandbox Code Playgroud)
struct AA
{
AA()
{
cout <<"BC"<<endl;
}
virtual ~AA()
{
cout <<"BD"<<endl;
}
};
struct AB: public AA
{
AB()
{
cout <<"DC"<<endl;
}
~AB() override
{
cout <<"DD"<<endl;
}
};
int main()
{
AA *x= new AB[1];
delete [] x;
return 0;
}
Run Code Online (Sandbox Code Playgroud)