Contents

OSDynamicCast

Casts an object safely to the specified type, if possible.

Declaration

#define OSDynamicCast(type, inst)

Parameters

  • type:

    The name of the desired class type as a raw token, not as a string or macro.

  • inst:

    The object to cast to the specified type.

Return Value

The object cast to the specified type, or NULL if the cast could not be performed safely.

Discussion

Use this macro instead of the standard C++ RTTI type-casting operator to cast objects to specific types. The following example shows how to cast some object to the OSString class. If the object cannot be cast to a string, the macro sets the string variable to NULL.

OSString string = OSDynamicCast(OSString, anObject)

See Also

Runtime support