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.