This documentation is archived and is not being maintained.


Enables objects of CObject-derived classes to be created dynamically at run time when used with the DECLARE_DYNCREATE macro.

IMPLEMENT_DYNCREATE(class_name, base_class_name )



The actual name of the class.


The actual name of the base class.

The framework uses this ability to create new objects dynamically, for example, when it reads an object from disk during serialization. Add the IMPLEMENT_DYNCREATE macro in the class implementation file. For more information, see CObject Class Topics.

If you use the DECLARE_DYNCREATE and IMPLEMENT_DYNCREATE macros, you can then use the RUNTIME_CLASS macro and the CObject::IsKindOf member function to determine the class of your objects at run time.

If DECLARE_DYNCREATE is included in the class declaration, then IMPLEMENT_DYNCREATE must be included in the class implementation.

Note that this macro definition will invoke the default constructor for your class. If a non-trivial constructor is explicitly implemented by the class, it must also explicitly implement the default constructor as well. The default constructor can be added to the class's private or protected member sections to prevent it from being called from outside the class implementation.

/* CAge.h */
class CAge : public CObject
     int m_Age;
     CAge( int Age ) { m_Age = Age; }
     CAge() { m_Age = 0; } // provide default constructor only for 
                           // dynamic creation 

/* CAge.cpp */
#include "stdafx.h"
#include "CAge.h"