#include <implicitdowncast.h>
Public Member Functions | |
ImplicitDowncast (B &base) | |
template<typename D > | |
operator D & () |
ImplicitDowncast< B > returns an object that can implictly be cast to classes derived from B. For example:
class base {}; class derived: public base {}; int main() { derived d; base *b = &d; base &b2 = ImplicitDowncast<base>(*b); derived &d2 = ImplicitDowncast<base>(*b); // Without ImplicitDowncast, C++ would require this instead: base &b3 = dynamic_cast<base&>(*b); derived &d3 = dynamic_cast<derived&>(*b); }
Note that no check is performed whether the cast will be succesful.