Home > Back-end >  Is there any way can solve the problem of multiple file reference each other
Is there any way can solve the problem of multiple file reference each other

Time:09-25

Recently in learning design patterns, the other two header files referenced problems, successfully settled through search engines, the result will use three header file reference each other, today don't know what to do, have great god know the solution,

CodePudding user response:

CodePudding user response:

Can't break it feel to be the infinite loop

CodePudding user response:

I am using stdafx. H header file, inside said earlier class XX;

CodePudding user response:

Define and implement separate written HPP split h CPP

CodePudding user response:

Using the interface, as far as possible is the relationship between modules is a tree, rather than the ring,

CodePudding user response:

Make sure you can each header file since the compiler through

CodePudding user response:

reference 4 floor jiquan393941336 response:
define and implement written separately the HPP split h CPP

Thank you very much! Why this happen??

CodePudding user response:

refer to fifth floor truth is right or wrong response:
using the interface, as far as possible is the relationship between modules is a tree, rather than the ring,

Well, I study how to use the interface implementation

CodePudding user response:

1, other classes as a forward declaration
2, in the class definition using other pointer or smart pointer class object, the constructor to pointer assignment
3, class implementation written in CPP in CPP header files included in other classes

CodePudding user response:

refer to 7th floor Mr_547 response:
Quote: refer to 4th floor jiquan393941336 response:

Define and implement written separately the HPP split h CPP

Thank you very much! Why this happen??


Nested repetition is implemented, the definition of a header file contains, the same function to achieve the twice, in the CPP was no problem, CPP file compiled only once, so design in addition to the most basic, also is some entity class can use HPP, other classes must be split, you can't guarantee a moment will appear containing each other, and libraries can be designed with HPP, logic of libraries will be less confusion, but also need to break up,

CodePudding user response:

references to the tenth floor jiquan393941336 response:
Quote: refer to 7th floor Mr_547 response:

Quote: refer to 4th floor jiquan393941336 response:

Define and implement written separately the HPP split h CPP

Thank you very much! Why this happen??


Nested repetition is implemented, the definition of a header file contains, the same function to achieve the twice, in the CPP was no problem, CPP file compiled only once, so design in addition to the most basic, also is some entity class can use HPP, other classes must be split, you can't guarantee a moment will appear containing each other, and libraries can be designed with HPP, logic of libraries will be less confusion, but also need to break up,

So that is what it boils down to
  • Related