CRuntimeClass::IsDerivedFrom

调用此函数确定调用的选件类是否在 pBaseClass 参数指定的选件类派生。

BOOL IsDerivedFrom(
   const CRuntimeClass* pBaseClass 
) const;

参数

  • pBaseClass
    CObject派生的选件类的熟悉的名称。

返回值

TRUE,如果调用 IsDerivedFrom 的选件类从 CRuntimeClass framework为作为参数的基类派生;否则 FALSE

备注

关系取决于“始终遵循”从派生类链成员的选件类为顶部。 匹配项,则也没有为基类,会出现此功能才返回 FALSE

备注

若要使用 CRuntimeClass 结构,必须在要检索运行时对象信息选件类的实现必须包含 IMPLEMENT_DYNAMICIMPLEMENT_DYNCREATEIMPLEMENT_SERIAL 宏。

有关使用 CRuntimeClass的更多信息,请参见文章 CObject选件类:访问运行时选件类信息

示例

// This example creates an object from the run-time class. It only 
// creates objects derived from CWnd.

// We only want to create an object derived from CWnd.
if (!pClass->IsDerivedFrom(RUNTIME_CLASS(CWnd)))
{
   TRACE(_T("Error; Object %s is not derived from CWnd\n"),
      pClass->m_lpszClassName);
   return FALSE;
}

// Get a pointer to the base class CRuntimeClass.
#ifdef _AFXDLL
   CRuntimeClass* pBaseClass = pClass->m_pfnGetBaseClass();
#else
   CRuntimeClass* pBaseClass = pClass->m_pBaseClass;
#endif
ASSERT(pBaseClass != NULL);

TRACE("Creating object %s derived from %s, with object size %d "
   "and schema %d\n", pClass->m_lpszClassName, 
   pBaseClass->m_lpszClassName, pClass->m_nObjectSize, 
   pClass->m_wSchema);

// Create the object.
CObject* pObject = pClass->CreateObject();

要求

Header: afx.h

请参见

参考

CRuntimeClass结构

层次结构图