is_base_of クラス

更新 : 2007 年 11 月

一方の型がもう一方の型の基本クラスであるかどうかをテストします。

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::tr1::is_base_of<base, base>::value << std::endl; 
    std::cout << "is_base_of<base, derived> == " << std::boolalpha 
        << std::tr1::is_base_of<base, derived>::value << std::endl; 
    std::cout << "is_base_of<derived, base> == " << std::boolalpha 
        << std::tr1::is_base_of<derived, base>::value << std::endl; 
 
    return (0); 
    } 
 
is_base_of<base, base> == true
is_base_of<base, derived> == true
is_base_of<derived, base> == false

必要条件

ヘッダー : <type_traits>

名前空間 : std::tr1

参照

参照

<type_traits>

is_convertible クラス