Page 1 of 1

Namespace across multiple files

Posted: Thu Jun 10, 2010 4:50 pm
by mv2112
Is it possible to do something like this:

Code: Select all

//engine.h
namespace CLASSES
{
#include "class.h"
#include "omg.h"
#include "0_o.h"
}
I want all of my classes to be within 1 namespace but they are split into header files.

Re: Namespace across multiple files

Posted: Thu Jun 10, 2010 8:50 pm
by Ginto8
Just have, in each header file, right inside the #ifndef guards and after any #includes:

Code: Select all

namespace blarg {
...
}
whether or not they're in the same namespace block, if they're in the namespace, you can treat it as though they're in the same scope. Provided you include the header file, that is.

Re: Namespace across multiple files

Posted: Thu Jun 10, 2010 9:32 pm
by dandymcgee
mv2112 wrote:Is it possible to do something like this:

Code: Select all

//engine.h
namespace CLASSES
{
#include "class.h"
#include "omg.h"
#include "0_o.h"
}
I want all of my classes to be within 1 namespace but they are split into header files.
Definitely don't do that, that would make all of the included files in your headers a part of your namespace as well. Ginto's suggestion is the right way to do it.