在这种情况下,工会成员会调用自己的析构函数吗
Will the members of a union member call their own destructors in this scenario?
当从联合中显式调用具有空dtor的类时,该类会调用其成员的dtor吗?
这有点难以形容,希望psuedo代码更直接。在本例中,Texture::~Texture()
是否会隐式调用source.bitmap.pixels.~vector()
?
struct Bitmap{
~Bitmap(){} // empty dtor
// members
std::vector<uint8> pixels; // <-- will this dealloc when ~Bitmap() is called manually?
};
struct Texture{
~Texture(){
// assume sourceType is 1
switch(sourceType){
case 1:
source.bitmap.~Bitmap();
break;
}
}
// members
uint sourceType;
union Source{
Source(){}
~Source(){}
// members
Bitmap bitmap;
}source;
};
析构函数的执行定义为执行析构函数函数体,然后执行对成员和基的析构函数调用。伪析构函数调用执行析构函数。
因此,是的,在这种情况下,伪析构函数调用将正确地销毁pixels
。
是的,它将隐式调用所有成员的析构函数,如果您的类是从另一个类派生的,它也将调用基类的析构因子。
相关文章:
- 什么时候调用组成单元对象的析构函数
- 为什么在使用转换构造函数赋值后调用C++类的析构函数?
- C++成员的析构函数顺序与shared_ptr
- 工会成员的析构函数似乎是自动调用的
- 放置上的析构函数 - 新
- 从 c++ 中派生类的析构函数调用虚函数
- 导致 Seg 错误的 SingleLinkedList 的析构函数
- 如何在 c++ 中的析构函数中正确释放合并 LL 的内存?
- 如何从 Gtk::窗口调用派生对象的析构函数
- typedef 别名的析构函数
- 为什么数组中对象的析构函数在被另一个对象替换时不被调用?
- 在这种情况下,工会成员会调用自己的析构函数吗
- 在元素自己的析构函数中擦除指向静态向量中元素的指针
- 定义自己的析构函数,尽管类派生自QObject
- 如果你的基类有一个虚拟析构函数,你自己的析构函数就会自动变成虚拟的
- 我必须在我自己的析构函数中手动重置shared_ptrs吗?
- 当我需要声明自己的析构函数时
- 什么时候需要声明自己的析构函数?
- 返回的结构调用它自己的析构函数,用于销毁分配的对象
- 在c++中使用a方法而不是类自己的析构函数的任何原因都要清除