std::has_virtual_destructor — cppreference.com
De cppreference.com
<metanoindex/>
<tbody> </tbody>
| Déclaré dans l'en-tête <type_traits> |
||
|
|
(depuis C++11) | |
Si T est un type avec un destructeur virtuel, fournit du membre de constante value true égale. Pour tout autre type, value est false .
Original:
If T is a type with a virtual destructor, provides the member constant value equal true. For any other type, value is false.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Inherited from std::integral_constant
Member constants
value [ statique Original: static The text has been machine-translated via Google Translate. |
Original:
The text has been machine-translated via Google Translate. (constante membre statique publique) |
Member functions
convertit l'objet en Original: converts the object to The text has been machine-translated via Google Translate. (fonction membre publique) | |
Member types
Type d' Original: Type The text has been machine-translated via Google Translate. |
Definition |
value_type
|
bool
|
type
|
std::integral_constant<bool, value>
|
Notes
Si une classe a un destructeur virtuel public, il peut être dérivé, et l'objet dérivé peut être supprimé en toute sécurité grâce à un pointeur sur l'objet de base (C++FAQ Lite 20.7)
Original:
If a class has a public virtual destructor, it can be derived from, and the derived object can be safely deleted through a pointer to the base object (C++FAQ Lite 20.7)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Exemple
#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'; }
Résultat :
std::string has a virtual destructor? false std::runtime_error has a virtual destructor? true