is_base_of-Klasse
Testet, ob ein Typ Basis von anderen ist.
template<class Base, class Derived>
struct is_base_of;
Parameter
Base
Die zu testen, Basisklasse.Derived
Der für abgeleitete Typ, zu testen.
Hinweise
Eine Instanz der Typprädikatgriffe True, wenn der Typ Base eine Basisklasse Typ Derived ist; andernfalls false hält er an.
Beispiel
// std_tr1__type_traits__is_base_of.cpp
// compile with: /EHsc
#include <type_traits>
#include <iostream>
struct base
{
int val;
};
struct derived
: public base
{
};
int main()
{
std::cout << "is_base_of<base, base> == " << std::boolalpha
<< std::is_base_of<base, base>::value << std::endl;
std::cout << "is_base_of<base, derived> == " << std::boolalpha
<< std::is_base_of<base, derived>::value << std::endl;
std::cout << "is_base_of<derived, base> == " << std::boolalpha
<< std::is_base_of<derived, base>::value << std::endl;
return (0);
}
Anforderungen
Header: <type_traits>
Namespace: std