Special member functions (destructor) - C++11, 19 of n

destructor
  1. A destructor is used to destroy objects of its class type. The address of a destructor shall not be taken. A destructor can be invoked for a const, volatile or const volatile object.const and volatile semantics are not applied on an object under destruction. They stop being in effect when the destructor for the most derived object  starts.
  2. A defaulted destructor for a class X is defined as deleted if:
    • X is a union-like class that has a variant member with a non-trivial destructor
    • any of the non-static data members has class type M (or array thereof) and M has a deleted destructor or a destructor that is inaccessible from the defaulted destructor
    • any direct or virtual base class has a deleted destructor or a destructor that is inaccessible from the defaulted destructor
    • or, for a virtual destructor, lookup of the non-array deallocation function results in an ambiguity or in a function that is deleted or inaccessible from the defaulted destructor.
  3. A destructor is trivial if it is not user-provided and if:
    • the destructor is not virtual,
    • all of the direct base classes of its class have trivial destructors, and
    • for all of the non-static data members of its class that are of class type (or array thereof), each such class has a trivial destructor.
  4. If a class has a base class with a virtual destructor, its destructor (whether user- or implicitly-declared) is virtual.
  5. destructor is implicitly invoked for constructed objects with thread storage duration at thread exit
  6. Note:
    • During object construction (constructor), be very careful the objects referenced have been fully initialized.
    • In constructor/destructor, pay close attention to calling "virtual function, dynamic_cast, typeid". They usually will NOT work as expected. So don't call these functions or operators in constructor/destructor.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值