共用方式為


CRuntimeClass::CreateObject

Call this function to dynamically create the specified class during run time.

CObject* CreateObject( ); 
static CObject* PASCAL CreateObject( 
   LPCSTR lpszClassName  
); 
static CObject* PASCAL CreateObject( 
   LPCWSTR lpszClassName  
);

Parameters

  • lpszClassName
    The familiar name of the class to be created.

Return Value

A pointer to the newly created object, or NULL if the class name is not found or there is insufficient memory to create the object.

Remarks

Classes derived from CObject can support dynamic creation, which is the ability to create an object of a specified class at run time. Document, view, and frame classes, for example, should support dynamic creation. For more information on dynamic creation and the CreateObject member, see CObject Class and CObject Class: Specifying Levels of Functionality.

Example

See the example for IsDerivedFrom.

Requirements

Header: afx.h

See Also

Reference

CRuntimeClass Structure

Hierarchy Chart