in the user defined headers? If yes, why?
For example instead of including iostream in my main.cpp program, I included iostream in myheader.h then just include myheader.h in my main.cpp program.
technically it will work fine but it will increase compilation time if let's say your header is included in 300 cpp files but really used in 10 files so usually you include headers in your header if it needed for this header (e.g. you include vector and you have a class that contains vector as a member) hope I make sense
Oh. Got it. Thank you. You are right. My example header propagated out over 3 files, which 2 of them don't require i/o at all. Thank you very much Pavel
But other than this problem, it doesn't make any problems or errors, yes?
should be no problem
Just know that adding of headers is the same as pasting content of all included headers. https://code.woboq.org/gcc/libstdc++-v3/include/std/iostream.html includes: https://code.woboq.org/gcc/libstdc++-v3/include/std/ostream.html https://code.woboq.org/gcc/libstdc++-v3/include/std/istream.html and each of them include other headers too. All of this code will be added every time you include your header.
Обсуждают сегодня