次の方法で共有


is_polymorphic クラス

型が仮想関数を持っているかどうかをテストします。

構文

template <class Ty>
struct is_polymorphic;

パラメーター

Ty
照会する型。

解説

Ty が仮想関数を宣言するか継承しているクラスである場合、型述語のインスタンスは true を保持します。それ以外の場合は、false を保持します。

// std__type_traits__is_polymorphic.cpp
// compile with: /EHsc
#include <type_traits>
#include <iostream>

struct trivial
    {
    int val;
    };

struct throws
    {
    throws() throw(int)
        {
        }

    throws(const throws&) throw(int)
        {
        }

    throws& operator=(const throws&) throw(int)
        {
        }

    virtual ~throws()
        {
        }

    int val;
    };

int main()
    {
    std::cout << "is_polymorphic<trivial> == " << std::boolalpha
        << std::is_polymorphic<trivial>::value << std::endl;
    std::cout << "is_polymorphic<throws> == " << std::boolalpha
        << std::is_polymorphic<throws>::value << std::endl;

    return (0);
    }
is_polymorphic<trivial> == false
is_polymorphic<throws> == true

必要条件

ヘッダー: <type_traits>

名前空間: std

関連項目

<type_traits>
is_abstract クラス