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
另請參閱
意見反映
https://aka.ms/ContentUserFeedback。
即將推出:我們會在 2024 年淘汰 GitHub 問題,並以全新的意見反應系統取代並作為內容意見反應的渠道。 如需更多資訊,請參閱:提交及檢視以下的意見反映: