如何在大型C ++项目中检测不必要的#include文件? [英] How should I detect unnecessary #include files in a large C++ project?

查看:185
本文介绍了如何在大型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?

推荐答案

虽然它不会显露不必要的包含文件,设置 / showIncludes (右键单击 .cpp 文件, Properties-> / C ++ - >高级),它将在编译时输出所有包含文件的树。这可以帮助识别不应该包含的文件。

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成语,以便减少更少的头文件依赖以便更容易查看您可以删除的垃圾。

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文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆