Share via


IMPLEMENT_DYNCREATE

IMPLEMENT_DYNCREATE(class_name,base_class_name)

Parameters

class_name

The actual name of the class (not enclosed in quotation marks).

base_class_name

The actual name of the base class (not enclosed in quotation marks).

Remarks

Use the IMPLEMENT_DYNCREATE macro with the DECLARE_DYNCREATE macro to enable objects of CObject-derived classes to be created dynamically at run time. 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 in Visual C++ Programmer’s Guide.

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.

Example

// CAge.h
class CAge : public CObject
{
     int num;
public:
     DECLARE_DYNCREATE(CAge)
};

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

IMPLEMENT_DYNCREATE(CAge, CObject)

See Also   DECLARE_DYNCREATE, RUNTIME_CLASS, CObject::IsKindOf