c++ - 为什么没有在clang中调用派生类析构函数
问题描述
为什么不使用 clang++ 10 调用派生的析构函数,它在 g++ 9 中按预期工作?为什么我会得到
BC
DC
BD
代替
BC
DC
DD
BD
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;
}
解决方案
推荐阅读
- css - 水平和垂直的flexbox css不起作用
- r - 如何通过R下的for循环将Wilcoxon测试应用于矩阵的每一行
- python - Python3:“functools.partial”的内部语法之谜
- reactjs - 动态路由 Reactjs
- generics - kotlin - 从类属性中删除可空性
- java - 我如何只运行一次此活动?
- python - 需要用 open & for 循环替换特定行(文本中的第一行)
- ios - 在同一个 ViewController 中打开文本文件
- python - 在 tkinter 中使用用户名和密码登录表单
- iframe - 如何保护原始源 (URL) 不被直接访问但同时允许我的 iFrame 加载受保护的页面?