1. The function of the information mechanism of the runtime class
Information about the object's related classes can be learned during the program's run
2, the use of the runtime class information mechanism
Class 2.1 must derive from the CObject class
Declare macros must be added within class 2.2 declare_dynamic
Implementation macro must be added outside of class 2.3 implement_dynamic
CObject::IsKindOf (...)-to determine whether an object belongs to a class
3. Data structure
struct CRuntimeClass
{
LPCSTR m_lpszClassName; The name of the class
int m_nobjectsize; The size of the class
UINT M_wschema; Version of the class
is used for dynamic creation mechanisms and is null when used for runtime class information mechanisms
cobject* (pascal* m_pfnCreateObject) ();
Cruntimeclass* M_pbaseclass; Parent class static variable address (link list)
Cruntimeclass* M_pnextclass; Is null
};
4, macro expansion of the code
5, the role of the various parts of the macro expansion
Classcdog-static variable, holds information about the class, joins a linked list
Getruntimeclass-virtual function, gets the address of this class static variable (gets the link header node)
6. IsKindOf Execution Process
6.1 Use the Cdog class object (Yellowdog) to invoke the virtual function getruntimeclass () to get the static variable address of the Cdog class (the node of the linked header)
6.2 Compare the static variables of the Cdog class to the target, and if equal, prove that the object belongs to this class, and if not equal gets the parent class static variable loop and the target is compared.
6.3 Only once equal can prove that the object belongs to this class
6.4 Cycle End is always more unsuccessful than the right to prove that the object does not belong to this class
Runtime_class (Theclass)-Returns the static variable address of the class in parentheses &theclass::classtheclass
Initial knowledge of MFC----Run-time class information mechanism