is_base_of クラス
一方の型がもう一方の型の基本クラスであるかどうかをテストします。
template<class Base, class Derived>
struct is_base_of;
パラメーター
Base
テスト対象の基本クラス。Derived
テスト対象の派生型。
解説
型 Base が型 Derived の基本クラスである場合、型述語のインスタンスは true を保持します。それ以外の場合は、false を保持します。
使用例
// 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);
}
必要条件
ヘッダー : <type_traits>
名前空間: std