I am new to C ++, but I understand that the #include statement essentially just removes the contents of the #included file to the location of this statement. This means that if there are a number of "#include" and "using" statements in my header file, my implementation file can simply # include the header file, and the compiler will not mind if I do not repeat other statements.
What about people?
My main problem is that if I do not repeat the statements '#include', 'using', as well as 'typedef' (now when I think about it), it takes this information away from the file in which it can lead to confusion.
I am just working on small projects at a time when it will not cause any problems, but I can imagine that in large projects with a large number of people working on them, this can become a serious problem.
Example:
UPDATE: the prototypes of my functions for 'Unit' have strings, ostream and StringSet among their types and return parameters. I do not include anything in my header file, which is used only in the implementation file.
//Unit.h #include <string> #include <ostream> #include "StringSet.h" using std::string; using std::ostream; class Unit { public: //public members with string, ostream and StringSet //in their return values/parameter lists private: //private members //unrelated side-question: should private members //even be included in the header file? } ; //Unit.cpp #include "Unit.h" //The following are all redundant from a compiler perspective: #include <string> #include <ostream> #include "StringSet.h" using std::string; using std::ostream; //implementation goes here
c ++ include header-files using-statement
David mason
source share