a必须要继承自CObject,还要加DECLARE_DYNAMIC
Call the IsKindOf member function for objects of that class, using the RUNTIME_CLASS macro to generate the CRuntimeClass argument, as shown here: // in .H file class CPerson : public CObject { DECLARE_DYNAMIC( CPerson ) public: CPerson(){}; // other declaration }; // in .CPP file IMPLEMENT_DYNAMIC( CPerson, CObject ) void SomeFunction(void) { CObject* pMyObject = new CPerson; if(pMyObject->IsKindOf( RUNTIME_CLASS( CPerson ) ) ) { //if IsKindOf is true, then cast is all right CPerson* pmyPerson = (CPerson*) pMyObject ; ... delete pmyPerson; } ... delete [MyObject]; } |
|