分享方式:


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 類別