Where do namespaces come from?

Hello,

I have never previously used any namespace other than std, however I have been reading about them and I don't understand where they come from. Everywhere I read about them there is no mention of how the compiler gets them. Does a namespace need to be defined in a separate file or does the compiler already have them? If so how would I go about using say my computer science professor's namespace? It seems he just includes it in his code and expects us to use it, but I don't see how the compiler would automatically be familiar with the namespace.

Thanks in advance
To use the classes and functions declared in that namespace,
You need to include the header file where he used it.
and then attach a prefix:
your_profs_ns::
to the stuff declared there.
You define namespaces like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
namespace myns
{
void SomeFunction();
}

// then you can use the namespace:

int main()
{
  myns::SomeFunction();

  // or if you prefer
  using namespace myns;
  SomeFunction();
}

Topic archived. No new replies allowed.