Initial knowledge of MFC----Run-time class information mechanism

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.