CObject::IsKindOf

Tests this object's relationship to a given class.

BOOL IsKindOf( 
   const CRuntimeClass* pClass  
) const;

Parameters

  • pClass
    A pointer to a CRuntimeClass structure associated with your CObject-derived class.

Return Value

Nonzero if the object corresponds to the class; otherwise 0.

Remarks

This function tests pClass to see if (1) it is an object of the specified class or (2) it is an object of a class derived from the specified class. This function works only for classes declared with the DECLARE_DYNAMIC, DECLARE_DYNCREATE, or DECLARE_SERIAL macro.

Do not use this function extensively because it defeats the C++ polymorphism feature. Use virtual functions instead.

Example

See CObList::CObList for a listing of the CAge class used in all CObject examples.

CAge a(21);  // Must use IMPLEMENT_DYNAMIC, IMPLEMENT _DYNCREATE, or 
             // IMPLEMENT_SERIAL
ASSERT(a.IsKindOf(RUNTIME_CLASS(CAge)));
ASSERT(a.IsKindOf(RUNTIME_CLASS(CObject)));   

Requirements

Header: afx.h

See Also

Tasks

Accessing Run-Time Class Information

Reference

CObject Class

Hierarchy Chart

CObject::GetRuntimeClass

RUNTIME_CLASS