Skip to content

Latest commit

 

History

History
49 lines (44 loc) · 1.4 KB

File metadata and controls

49 lines (44 loc) · 1.4 KB
title Dynamic Object Creation | Microsoft Docs
ms.custom
ms.date 11/04/2016
ms.reviewer
ms.suite
ms.technology
cpp-windows
ms.tgt_pltfrm
ms.topic article
dev_langs
C++
helpviewer_keywords
object creation, dynamically at run time
CObject class, dynamic object creation
objects [C++], creating dynamically at run time
dynamic object creation
ms.assetid 3e0f51cb-3e24-4231-817f-1c0ce9f2d5df
caps.latest.revision 10
author mikeblome
ms.author mblome
manager ghogen
translation.priority.ht
cs-cz
de-de
es-es
fr-fr
it-it
ja-jp
ko-kr
pl-pl
pt-br
ru-ru
tr-tr
zh-cn
zh-tw

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

  1. 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:

    [!code-cppNVC_MFCCObjectSample#6]

See Also

Using CObject