[][src]Trait cpp_core::DynamicCast

pub trait DynamicCast<T>: Sized {
    unsafe fn dynamic_cast(ptr: Ptr<Self>) -> Ptr<T>;

Converts a class pointer to a base class pointer.

A null pointer is always converted to a null pointer. If the object can't be converted to the requested type, a null pointer is returned.

It's recommended to perform the conversion by calling dynamic_cast method on pointer types (CppBox, Ptr, Ref) instead of importing the trait directly.

Provides access to C++ dynamic_cast conversion from base class to derived class. The conversion in opposite direction can be done with StaticUpcast.

If T1 class is derived (in C++) from T2 class (directly or indirectly), DynamicCast<T1> is implemented for T2. The implementation is generated by ritual automatically.

Required methods

unsafe fn dynamic_cast(ptr: Ptr<Self>) -> Ptr<T>

Convert type of a const pointer.

Returns a null pointer if the object doesn't have the requested type.


This operation is safe as long as ptr is either valid or null.

Loading content...


Loading content...