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.
Dynamically create an object given its run-time class
Use the following code to dynamically create an object using the
CreateObject
function of theCRuntimeClass
. 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
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for