我应该如何检测大型 C++ 项目中不必要的 #include 文件?

2023-12-03C/C++开发问题
2

本文介绍了我应该如何检测大型 C++ 项目中不必要的 #include 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在 Visual Studio 2008 中处理一个大型 C++ 项目,并且有很多文件带有不必要的 #include 指令.有时 #include 只是工件,删除它们后一切都会很好地编译,而在其他情况下,可以向前声明类,并且可以将 #include 移动到 .cpp 文件.有没有什么好的工具可以检测这两种情况?

I am working on a large C++ project in Visual Studio 2008, and there are a lot of files with unnecessary #include directives. Sometimes the #includes are just artifacts and everything will compile fine with them removed, and in other cases classes could be forward declared and the #include could be moved to the .cpp file. Are there any good tools for detecting both of these cases?

推荐答案

虽然它不会显示不需要的包含文件,但 Visual Studio 有一个设置 /showIncludes(右键单击 .cpp 文件,Properties->C/C++->Advanced) 将在编译时输出所有包含文件的树.这有助于识别不需要包含的文件.

While it won't reveal unneeded include files, Visual studio has a setting /showIncludes (right click on a .cpp file, Properties->C/C++->Advanced) that will output a tree of all included files at compile time. This can help in identifying files that shouldn't need to be included.

您还可以查看 pimpl idiom,以减少头文件依赖项,从而更轻松地查看可以删除的内容.

You can also take a look at the pimpl idiom to let you get away with fewer header file dependencies to make it easier to see the cruft that you can remove.

这篇关于我应该如何检测大型 C++ 项目中不必要的 #include 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

无法访问 C++ std::set 中对象的非常量成员函数
Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)...
2024-08-14 C/C++开发问题
17

从 lambda 构造 std::function 参数
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)...
2024-08-14 C/C++开发问题
25

STL BigInt 类实现
STL BigInt class implementation(STL BigInt 类实现)...
2024-08-14 C/C++开发问题
3

使用 std::atomic 和 std::condition_variable 同步不可靠
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)...
2024-08-14 C/C++开发问题
17

在 STL 中将列表元素移动到末尾
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)...
2024-08-14 C/C++开发问题
9

为什么禁止对存储在 STL 容器中的类重载 operator&()?
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)...
2024-08-14 C/C++开发问题
6