I was just wondering if someone could tell me what namespace is. How, when and why one should use it would be nice also
Best Regards,
Purre
I was just wondering if someone could tell me what namespace is. How, when and why one should use it would be nice also
Best Regards,
Purre
a namespace is a device for limiting name clashes in large projects. You can think of it as a package in which "everything else" is held. Until you get beyond the basics of programming in C++ you don't have to worry about this too much. Once you start working on large projects with several development teams, etc., it is supposed to make life easier. The way it's defined is you have always been working in namespace std, but now you should explicitly declare it.
Code:#include <iostream> using namespace std; namespace cheese { int x; } namespace frog { int x; } int main(void) { cout << "How old is your cheese?" << endl; cin >> cheese::x; cout << "How old is your frog?" << endl; cin >> frog::x; cout << "so you are trying to tell me your cheese is " << cheese::x << " years old?" << endl; cout << "and your frog is " << frog::x << " years old?" << endl; return 0; }