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];
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。