Could somebody please explain to me the differences between "#include"-ing header files, and the "using namespace" code and what each does? Thanks :]
Could somebody please explain to me the differences between "#include"-ing header files, and the "using namespace" code and what each does? Thanks :]
"#include" takes the whole text of a file and places it in this file.
"using namespace" is a completely different thing;
For C++ to avoid name collisions between same function names, there is an option that we declare a function not global, but part of a namespace.
Example:
"using namespace" just makes all functions under this namespace globalCode:#include <iostream> int main() { std::cout << "Hello World!"; std::cin.get(); return 0; }
Code:#include <iostream> using namespace std; int main() { cout << "Hello World!"; cin.get(); return 0; }
Devoted my life to programming...
So in your second example, int main and anything below it would be considered a global function?
Exactly
Devoted my life to programming...
so in a weird way namespaces are like groups of functions?
and using a namespace just allows you to call any of those functions from within that cpp file?
and header files are basically just a list of variables, prototypes, and other stuff like that
My bad, when i say "under the namespace" i mean "declared and/or defined inside the namespace". I should've though that you'd take it literally...
Devoted my life to programming...
Well yeah, I figured that much. Thanks for the help :]