In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
For gadgets, it is estimated that there are only a few files written in C++, and there are few compilation errors caused by the mutual inclusion of design header files.
However, as the software functions become more and more complex, and the call relationship between the modules becomes less and less obvious, it is very likely that the A header file contains the B header file and the B header file contains the A header file. this mutual inclusion of header files can lead to errors in which the compilation type cannot be found.
The simplest code is as follows:
A.h is as follows
# include "B.H" class A {B b;}
A.cpp is as follows
# include "A.H" class A {...}
B.H is as follows
# include "A.h" class B {AA;}
B.cpp is as follows
# include "B.H" class B {...}
If the file is in this case, the compilation cannot find the type, because A contains the B header file in the header file, and B contains the A header file, which can cause compilation errors.
Solution.
The solution is a pre-declaration.
The modified code is as follows
A.h is as follows
Class B _ class A {B _ b;}
A.cpp is as follows
# include "A.H" # include "B.H" class A {...}
B.H is as follows
Class Aclass B {An a;}
B.cpp is as follows
# include "B.H" # include "A.H" class B {...}
What if you want to do it once and for all?
For the header files of frequently used modules, you can write a unified pre-declaration file, write all the commonly used declarations into the header file, such as includeDeclare.h, and then put the actual header files into a file, such as includeHeaders.h. So when you use it in other places later, just introduce includeDeclare.h in the header file and includeHeaders.h in the implementation cpp file.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.