std::has_virtual_destructor
STD::HAS[医]虚拟[医]破坏者
Defined in header | | |
---|---|---|
template< class T > struct has_virtual_destructor; | | (since C++11) |
如果T
是具有虚拟析构函数的类型,提供成员常量。value
平等true
.对于任何其他类型,value
是false
...
如果T
是非工会类类型,T
应该是一个完整的类型;否则,该行为是未定义的。
辅助变量模板
template< class T > inline constexpr bool has_virtual_destructor_v = has_virtual_destructor | | (since C++17) |
---|
继承自STD:积分[医]常量
成员常数
value static | true if T has a virtual destructor , false otherwise (public static member constant) |
---|
成员函数
operator bool | converts the object to bool, returns value (public member function) |
---|---|
operator() (C++14) | returns value (public member function) |
成员类型
Type | Definition |
---|---|
value_type | bool |
type | std::integral_constant<bool, value> |
注记
如果类具有公共虚拟析构函数,则可以从它派生,并且可以通过指向基对象%28的指针安全地删除派生对象。GotW#1829%。
例
二次
#include <iostream>
#include <type_traits>
#include <string>
#include <stdexcept>
int main()
{
std::cout << std::boolalpha
<< "std::string has a virtual destructor? "
<< std::has_virtual_destructor<std::string>::value << '\n'
<< "std::runtime_error has a virtual destructor? "
<< std::has_virtual_destructor<std::runtime_error>::value << '\n';
}
二次
产出:
二次
std::string has a virtual destructor? false
std::runtime_error has a virtual destructor? true
二次
另见
is_destructibleis_trivially_destructibleis_nothrow_destructible (C++11)(C++11)(C++11) | checks if a type has a non-deleted destructor (class template) |
---|
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。