Skip to content

Latest commit

 

History

History
76 lines (56 loc) · 1.49 KB

is-base-of-class.md

File metadata and controls

76 lines (56 loc) · 1.49 KB
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Learn more about: is_base_of Class
is_base_of Class
11/04/2016
type_traits/std::is_base_of
is_base_of class
is_base_of
436f6213-1d4c-4ffc-a588-fc7c4887dd86

is_base_of Class

Tests whether one type is base of another.

Syntax

template <class Base, class Derived>
struct is_base_of;

Parameters

Base
The base class to test for.

Derived
The derived type to test for.

Remarks

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

Example

#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::is_base_of<base, base>::value << std::endl;
    std::cout << "is_base_of<base, derived> == " << std::boolalpha
        << std::is_base_of<base, derived>::value << std::endl;
    std::cout << "is_base_of<derived, base> == " << std::boolalpha
        << std::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

Requirements

Header: <type_traits>

Namespace: std

See also

<type_traits>
is_convertible Class