include stdafx.h in header or source file?

后端 未结 2 1551
梦谈多话
梦谈多话 2020-12-10 12:46

I have a header file called stdafx.h and this one is precompiled of course. I\'ve read that I should include these files into my .cpp files, but some of these statements are

2条回答
  •  青春惊慌失措
    2020-12-10 13:15

    • Only include things in your precompiled header which should be there
    • Your precompiled header file must be the first include in every .cpp
    • I would avoid including it in another header in favor of forward declaration

    Ask yourself these two questions before including something in stdafx.h

    1. Will this header never be changed by me?
    2. Do I need this included in every multiple source file?

    If the answer is "No" to either of those then don't include it.

提交回复
热议问题