22

I notice that C++'s std namespace is spread across several files (like in vector, string, iostream, etc.). How can I accomplish the same thing in my programs? Do I simply declare the same namespace in each individual header file, so that it's something like:

a.h

namespace something
{
class A {};
}

b.h

#include "a.h"

namespace something
{
class B : public A {};
}

And then in, say, main.cpp, I would just include "b.h" and "a.h" and then using namespace something; to use the two classes?

Remy Lebeau
  • 505,946
  • 29
  • 409
  • 696
wrongusername
  • 17,664
  • 35
  • 123
  • 208

1 Answers1

24

Yes, that is exactly how to do it.

Andrew Hare
  • 333,516
  • 69
  • 632
  • 626