I have a question about how I should layout the codes for namespace.
Assume in my code I have three class a, b, c and I want to put them in namespace own
Then I plan to create file ownlib.h and ownlib.cpp
in ownlib.h, I put all three class declarations as:
namespace own
{
class a
{
private:
public : func1
}
class b
{
private:
public : func1
}
class c
{
private:
public : func1
}
}
in ownlib.c,I put three class declarations as:
#include "ownlib.h"
namespace own
{
void a::func1();
void b::func1();
void c::func1();
}
Is this the right layout?
Based my understanding, I can compile these two files (.h and .cpp) to static library to be a ownlib.lib file.
But namespace and library should be two different concepts. So I have following questions:
1. Can I add class D, which is in namespace own, but not in library ownlib? If I can, how?
2. Can I add class D, which is in library ownlib, but not in namespace own? If I can, how?
namespace is what it imply: a naming convention. So you can put the class D in any namespace you want no matter whether that namespace already exists or not.
Yes it is irrelevant if and in what context the namespace appears. Just avoid name conflicts.
Whether the class D appears in the library ownlib depends on your project setting (which depends on the IDE you're using, basically: tell the IDE that you want the file associated with class D in ownlib)