Namespaces
Variants

std:: has_virtual_destructor

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
(C++11) ( until C++20* )
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
Type modifications
Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
헤더에 정의됨 <type_traits>
template < class T >
struct has_virtual_destructor ;
(C++11부터)

std::has_virtual_destructor UnaryTypeTrait 입니다.

만약 T 가 가상 소멸자를 가진 타입이라면, 기본 특성은 std::true_type 입니다. 다른 모든 타입에 대해서는 기본 특성은 std::false_type 입니다.

만약 T 가 불완전한 비공용체 클래스 타입인 경우, 동작은 정의되지 않습니다.

프로그램이 std::has_virtual_destructor 또는 std::has_virtual_destructor_v 에 대한 특수화를 추가하는 경우, 그 동작은 정의되지 않습니다.

목차

템플릿 매개변수

T - 확인할 타입

헬퍼 변수 템플릿

template < class T >
constexpr bool has_virtual_destructor_v = has_virtual_destructor < T > :: value ;
(C++17부터)

std:: integral_constant 로부터 상속됨

멤버 상수

value
[static]
true 만약 T 가 가상 소멸자를 가지면, false 그렇지 않으면
(public static member constant)

멤버 함수

operator bool
객체를 bool 로 변환, value 반환
(public member function)
operator()
(C++14)
value 반환
(public member function)

멤버 타입

타입 정의
value_type bool
type std:: integral_constant < bool , value >

참고 사항

만약 클래스 C 가 public 가상 소멸자를 가지고 있다면, 이 클래스는 파생될 수 있으며, 파생된 객체는 기본 객체에 대한 포인터를 통해 안전하게 삭제될 수 있습니다 ( GotW #18 ). 이 경우, std:: is_polymorphic < C > :: value true 입니다.

예제

#include <type_traits>
struct S {};
static_assert(!std::has_virtual_destructor_v<S>);
struct B { virtual ~B() {} };
static_assert(std::has_virtual_destructor_v<B>);
struct D : B { ~D() {} };
static_assert(std::has_virtual_destructor_v<D>);
int main()
{
    B* pd = new D;
    delete pd;
}

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 2015 C++11 T 가 불완전한 공용체 타입인 경우
동작이 정의되지 않음
이 경우 기본 특성은
std::false_type

참고 항목

해당 타입이 삭제되지 않은 소멸자를 가지고 있는지 확인합니다
(클래스 템플릿)
해당 타입이 다형 클래스 타입인지 확인합니다
(클래스 템플릿)