次の方法で共有


is_base_of クラス

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

構文

template <class Base, class Derived>
struct is_base_of;

パラメーター

Base
テスト対象の基底クラス。

派生
テスト対象の派生型。

解説

Base が型 Derived の基底クラスである場合、型述語のインスタンスは true を保持します。それ以外の場合は、false を保持します。

#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);
    }
is_base_of<base, base> == true
is_base_of<base, derived> == true
is_base_of<derived, base> == false

必要条件

ヘッダー: <type_traits>

名前空間: std

関連項目

<type_traits>
is_convertible クラス