The Declaration sequence and structure sequence of the member variables in MFC, and the declaration of the mfc member variables

Source: Internet
Author: User

The Declaration sequence and structure sequence of the member variables in MFC, and the declaration of the mfc member variables

I used my blog for the first time and wrote the first article casually. Let's write a question that I encountered today.

In the MFC Dialog Box program of VS2008, the Declaration Order of window member variables is the opposite to that of window member variables. That is, the Declaration result is the declaration result and the declaration result is the first analysis result. Not tested in other modes.

Class A {public: A () {MessageBox (NULL, "A constructor", "A", MB_ OK );}~ A () {MessageBox (NULL, "A destructor", "A", MB_ OK); // the dialog box is not displayed.}; class B {public: B () {MessageBox (NULL, "B constructor", "B", MB_ OK );}~ B () {MessageBox (NULL, "B destructor", "B", MB_ OK); // the dialog box is not displayed }};

Then declare the variable in the dialog box class.

A a; B B;

Run the program. The "A constructor" dialog box appears, and the "B constructor" dialog box appears.

Close the program. After debugging, you can find that the "B destructor" dialog box is called first, and then the "A destructor" dialog box is called. But in fact these two dialogs do not appear, probably because the program exits, and MFC stops the window pop-up.

 

Conclusion: The declared variables are parsed first, and then declared variables are parsed first.

This is often useful when A and B are coupled. For example, B uses A member. If A first analyzes the structure and B's thread has not exited, overflow may occur, or the exit of the dialog box interface but the process has not ended.

Related Article

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.