When using Microsoft's Fast Compilation design -stdafx.h
- is the idea that all includes should only ever occur in this file only.
Not all headers should be placed in stdafx.h
, as @drescherjm commented.
Moreover, even if a header appears in stdafx.h
, it does not automatically mean that it should disappear from cpp
files. At least, according to 4 Ways Precompiled Headers Cripple Your Code (although not about Microsoft, but the same principle, emphasis mine):
Apple’s iOS project templates start you off with Prefix.pch including Foundation and UIKit. From a compilation speed point of view, this makes a lot of sense. The problem is that people noticed and said, “Those files are already implicitly included. So I don’t need to include them again.” Upon discovering this side-effect, some programmers start dumping more headers into Prefix.pch. Because hey, then you don’t have to #import it ever again.
The purpose shifted from “make this project compile as fast as possible” to “save myself some typing.” A Stack Overflow question reflects this, asking, “Why have both?” Even the Wikipedia entry for prefix header reflects this incorrect conclusion: “As a result, it is unnecessary to explicitly include any of the above files.” This misunderstanding is widespread.
And it’s flat-out wrong.
....
The problem is that to successfully compile a file, it’s no longer enough to have the paired header (.h) and the implementation (.m). You also need Prefix.pch — not because they’re precompiled, but because they’re implicitly included.
And they give several points, basically elaborating on the idea that it breaks the concept of dependency.