std::is_base_of
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <type_traits> 中定义
|
||
template< class B, class D > struct is_base_of; |
(C++11 起) | |
如果
D
是来自B
或者如果两者是相同的非工会类,成员常量value
等于true。否则value
是false.原文:
If
D
is derived from B
or if both are the same non-union class, provides the member constant value
equal to true. Otherwise value
is false.目录 |
Inherited from std::integral_constant
Member constants
value [静态的]</div></div>
|
true如果 D is derived from B ,false其他方式 原文: true if D is derived from B , false otherwise (公共静态成员常量) |
Member functions
operator bool |
转换的对象bool,返回 value 原文: converts the object to bool, returns value (公共成员函数) |
Member types
类型
|
Definition |
value_type
|
bool
|
type
|
std::integral_constant<bool, value> |
</div>
[编辑] 示例
#include <iostream> #include <type_traits> class A {}; class B : A {}; class C {}; int main() { std::cout << std::boolalpha; std::cout << "a2b: " << std::is_base_of<A, B>::value << '\n'; std::cout << "b2a: " << std::is_base_of<B, A>::value << '\n'; std::cout << "c2b: " << std::is_base_of<C, B>::value << '\n'; }
输出:
a2b: true b2a: false c2b: false