is_polymorphic Class

 

The latest version of this topic can be found at is_polymorphic Class.

Tests if type has a virtual function.

Syntax

template <class Ty>  
struct is_polymorphic;  

Parameters

Ty
The type to query.

Remarks

An instance of the type predicate holds true if the type Ty is a class that declares or inherits a virtual function, otherwise it holds false.

Example

// std_tr1__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  

Requirements

Header: <type_traits>

Namespace: std

See Also

<type_traits>
is_abstract Class