25

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
  • 555,201
  • 31
  • 458
  • 770
wrongusername
  • 18,564
  • 40
  • 130
  • 214

1 Answers1

26

Yes, that is exactly how to do it.

Andrew Hare
  • 344,730
  • 71
  • 640
  • 635