Export (0) Print
Expand All

is_base_of Class

Tests if one type is base of another.

template<class Base, class Derived>
    struct is_base_of;

Base

The base class to test for.

Derived

The derived type to test for.

An instance of the type predicate holds true if the type Base is a base class of the type Derived, otherwise it holds false.

 

// std_tr1__type_traits__is_base_of.cpp 
// compile with: /EHsc 
#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::tr1::is_base_of<base, base>::value << std::endl; 
    std::cout << "is_base_of<base, derived> == " << std::boolalpha 
        << std::tr1::is_base_of<base, derived>::value << std::endl; 
    std::cout << "is_base_of<derived, base> == " << std::boolalpha 
        << std::tr1::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

Header: <type_traits>

Namespace: std::tr1

Community Additions

ADD
Show:
© 2014 Microsoft