STATIC_DOWNCAST
TRY
TOC
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

STATIC_DOWNCAST 

Casts pobject to a pointer to a class_name object.


STATIC_DOWNCAST(class_name, pobject )

Parameters

class_name

The name of the class being cast to.

pobject

The pointer to be cast to a pointer to a class_name object.

pobject must either be NULL, or point to an object of a class which is derived directly, or indirectly, from class_name. In builds of your application with the _DEBUG preprocessor symbol defined, the macro will ASSERT if pobject is not NULL, or if it points to an object that is not a "kind of" the class specified in the class_name parameter (see CObject::IsKindOf). In non-_DEBUG builds, the macro performs the cast without any type checking.

The class specified in the class_name parameter must be derived from CObject and must use the DECLARE_DYNAMIC and IMPLEMENT_DYNAMIC, the DECLARE_DYNCREATE and IMPLEMENT_DYNCREATE, or the DECLARE_SERIAL and IMPLEMENT_SERIAL macros as explained in the article CObject Class: Deriving a Class from CObject.

For example, you might cast a pointer to CYourDocument, called pYourDoc, to a pointer to CDocument using this expression:

CDocument* pDoc = STATIC_DOWNCAST(CDocument, pYourDoc);

If pYourDoc does not point to an object derived directly or indirectly from CDocument, the macro will ASSERT.

Show:
© 2016 Microsoft