Namespace

Mar 11, 2011 at 5:48pm
Is it possible to save a namespace as a library, and use it without having to rewrite the code? Like namespace std? I made a namespace called, "Namespace blackjack" and then made a bunch of functions and stuff, but I want to know if I can save it as a library/directory so that I can just call functions from it without re-defining the functions.

Thanks.
Mar 11, 2011 at 5:55pm
You can write a library and put every symbol of that library in a namespace.
Then you'll have to #include the header of your library as usual
Mar 11, 2011 at 5:58pm
Header files.
Last edited on Mar 11, 2011 at 5:58pm
Mar 11, 2011 at 6:00pm
How do I create this library and include it?
Mar 11, 2011 at 6:06pm
Like that:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//header.h
#ifndef MY_HEADER_GUARDER
#define MY_HEADER_GUARDER
namespace MyNamespace
{
//Declarations
}
#endif //MY_HEADER_GUARDER
//Implementations.cpp
#include <header.h>
namespace MyNamespace
{
//Implementation of your classes, functions etc
}


Then you'd just distribute the header along with the object file. If you have multiple object files, you'd want to create a library for them - how you do that depends on the linker you are using. You can then use everything declared in header.h if you include it, and link your object file.
Last edited on Mar 11, 2011 at 6:13pm
Mar 11, 2011 at 6:46pm
It seems you don't even need an namepace try a object: http://www.cplusplus.com/doc/tutorial/classes/
or simple header file instead.

Topic archived. No new replies allowed.