Namespace across multiple files

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
mv2112
Chaos Rift Junior
Chaos Rift Junior
Posts: 240
Joined: Sat Feb 20, 2010 4:15 am
Current Project: Java Tower Defence Game
Favorite Gaming Platforms: N64/Xbox 360/PC/GameCube
Programming Language of Choice: C/++, Java
Location: /usr/home/mv2112
Contact:

Namespace across multiple files

Post 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.
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Namespace across multiple files

Post 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.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Namespace across multiple files

Post 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.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
Post Reply