如何正确使用stdafx.h? [英] How to use stdafx.h properly?

查看:361
本文介绍了如何正确使用stdafx.h?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 stdafx.h 的方式是否可以分离依赖关系?

What is the proper way to use stdafx.h, in terms of separating dependencies?

如果我把一切放在那里,那么我的编译快速,我需要在任何文件中说:

If I put everything in there, then my compiles are blazing fast, and all I need to say in any file is

#include "stdafx.h"


  1. 我不再知道哪些文件取决于哪些标头。

  2. 我的代码不太可重用。

  3. 我不能再从C ++中分离C #include string.h )没有太大的痛苦。

  1. I no longer know which files depend on which headers.
  2. It reduces modularity, making my code less reusable.
  3. I can no longer separate C #includes from C++ ones (e.g. cstring versus string.h) without a great deal of pain. (Speaking of which, does this even matter?)

如果我把没有放在那里,我可以

If I put nothing in there, I can organize everything well -- but then my compiles slow down dramatically.


推荐答案

您不应该将自己的头文件放在 stdafx.h ,因为你的代码可能会改变,并且会导致整个程序重新编译。

You shouldn't put your own header files in stdafx.h since your code is likely to change and will cause your whole program to recompile.

我通常在其中放置标准标题和其他库,例如所有boost包括。

I usually put standard headers and other libraries in there, such as all boost includes.

这篇关于如何正确使用stdafx.h?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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