Export (0) Print
Expand All
2 out of 9 rated this helpful - Rate this topic

Dynamic Object Creation 

This article explains how to create an object dynamically at run time. The procedure uses run-time class information, as discussed in the article Accessing Run-Time Class Information.

To dynamically create an object given its run-time class

  • Use the following code to dynamically create an object by using the CreateObject function of the CRuntimeClass. Note that on failure, CreateObject returns NULL instead of raising an exception:

    CRuntimeClass* pRuntimeClass = RUNTIME_CLASS( CMyClass );
    CObject* pObject = pRuntimeClass->CreateObject();
    ASSERT( pObject->IsKindOf( RUNTIME_CLASS( CMyClass ) ) );
    

See Also

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.