Creep2DJ Creep2DJ - 2 months ago 7
C++ Question

If I #include a header file in a non-main source file, do I need to also do that in the main file?

I have a file

item.cpp
, in which
<algorithm>
is #included. Do I need to include in
main.cpp
as well? Or may I leave it alone?

Answer

You need to add #include <algorithm> to main.cpp if main.cpp uses any functions or classes, or anything else that's defined in <algorithm>.

What some other translation unit uses is irrelevant.

Comments