This forum is deprecated.
Why should you care about header dependencies in C++? One reason is header dependencies can have an impact on building, refactoring, testing and on the structure of your software.
And reducing header dependencies in C++ also reduces compile time dependencies – the dependencies between files and libraries at compile time.
One way to reduce header dependencies in C++ is to avoid including headers inside other header files.
In C++ Builder, Project Options | Project Properties, select Show Header dependencies in project manager and also select Index files for “Definitions and References’ :
Then in the C++ Code Editor, | right-click an identifier | Find > Header Dependency
Note: This command is available only for 64-bit Windows, iOS, and Android target platforms.
This command searches the entire active project for the header dependencies. It opens the Header Dependency pane, which contains the following information:
Using the C++ Builder Header Dependency, for the above Averages.h header file we get this:
The Header Dependency info is embedded in the object file (WIN32), or is an external .d file for other target platforms. (See here).
The IDE views on these links header dependencies view and Header Dependency Results read the information from the object file, or the .d file directly. The information from the object can be dumped using tdump. The .d is a plain text file with a standard format.
Does this mean that forward declaration isn’t possible with std::list ?
One workaround is if we define our own non-templated list class and uses that instead, we wouldn’t have these issues with predeclaration. But implementing our own list class isn’t easy, and we don’t get all the benefits of std::list‘s implementation. But we can use something like this, in CustomList.h:
And then we can create a NewAverages.h, like this:
Now we have the situation where clients of the Averagers class who use the std::list function must include the "CustomList.h"header, and have the dependencies and compile time of #include <list>.
Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder. Design. Code. Compile. Deploy.
Start Free Trial
Free Delphi Community Edition
Free C++Builder Community Edition