Surprisingly, the only really similar question I found (Advantages of removing includes which are already in precompiled header?) only asks for possible compile time gains, and mentions there are disadvantages but without specifying what these might be. There are other related questions but these concern including headers in headers and not directly in translation units, so I wanted to ask specifically about this.
Consider:
precompile.hpp
#ifndef PRECOMPILE_H
#define PRECOMPILE_H
#include <string>
#include <iostream>
#endif // PRECOMPILE_H
precompile.cpp
#include "precompile.hpp"
main.cpp
#include "precompile.hpp"
#include <string>
#include <iostream>
int main()
{
std::string str = "hello";
std::cout << str << "\n";
}
Are there any major recommendations as to whether or not to explicitly include, in the source file, headers that are precompiled (<string>
and <iostream>
in my example)?