Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for a snapshot of the master branch, built from commit b9ab49fc70.
PrevUpHomeNext

Macro BOOST_TYPE_INDEX_REGISTER_CLASS

BOOST_TYPE_INDEX_REGISTER_CLASS

Synopsis

// In header: <boost/type_index.hpp>

BOOST_TYPE_INDEX_REGISTER_CLASS

Description

BOOST_TYPE_INDEX_REGISTER_CLASS is used to help to emulate RTTI. Put this macro into the public section of polymorphic class to allow runtime type detection.

Depending on the typeid() availability this macro will expand to nothing or to virtual helper function virtual const type_info& boost_type_info_type_id_runtime_() const noexcept.

Example:

class A {
public:
    BOOST_TYPE_INDEX_REGISTER_CLASS
    virtual ~A(){}
};

struct B: public A {
    BOOST_TYPE_INDEX_REGISTER_CLASS
};

struct C: public B {
    BOOST_TYPE_INDEX_REGISTER_CLASS
};

...

C c1;
A* pc1 = &c1;
assert(boost::typeindex::type_id<C>() == boost::typeindex::type_id_runtime(*pc1));


PrevUpHomeNext