0

I'm a beginner to C++ and I am getting extremely confused trying to understand the benefits of the recommended practices regarding headers and implementation files.

Say I have two implementation files for two separate parts of my program and they both require iostream and sstream. Is this a bad thing and should it, or can it be avoided? I know that I'm supposed to avoid redundant includes, is this considered redundant?

  • 3
    _" is this considered redundant?"_ No. – πάντα ῥεῖ Oct 08 '15 at 22:41
  • Damn. This was a good question. – user4581301 Oct 08 '15 at 22:44
  • Uncovered addendum: Always include all required headers. You can have an unnecessary header if no functionality from the header is used by the including file, but the only way to have a redundant header is to include the same header in the same file twice. If A.cpp needs B.h and string and B.h already includes string, include both B.h and string in A.cpp anyway. That way if the maintainer of B.h removes the include of string, A.cpp still compiles. – user4581301 Oct 08 '15 at 22:52
  • @user4581301 Vote to reopen it, if you think it's worth it, and will gather valuable information beyond the marked duplicate already contains in answers. Or even better if you think that additional, but missing, information is that important, add another answer over there. – πάντα ῥεῖ Oct 09 '15 at 00:33
  • @πάνταῥεῖ considered the reopen vote, but the comment should suffice. It's not something that takes long to explain or requires formatted code. Addin to the other question is a non starter. It's locked, and "Why have them" and "When should I include them" are different questions. – user4581301 Oct 09 '15 at 00:49

0 Answers0