Cross-contained header files

Source: Internet
Author: User

I have been confused about the problem of two header files that contain each other.

Link. h

# Include "node. H"

Class Link

{

PRIVATE:

Node * m_node;

};

Node. h

# Include "link. H"

Class Node

{

PRIVATE:

Link * m_link;

};

The # include statement of both files is placed in the # ifndef macro.

In this way, VC will tell you that you do not know one of the classes (the one compiled later ). Only the class link is added before the class node;

Can be compiled successfully.

I keep thinking, why? This involves a question: how does the VC compiler compile the program?

I think: when compiling each header file, VC will expand other header files contained in this header file and compile it with. cpp of the same name. This

A process is an independent process. However, after the header files that contain each other are expanded, the repeatedly defined header files will not be inserted into the entire. OBJ file.

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.