Namespace in the definition and implementation

If you have a header file, say "test.h" , including

namespace test
{
   enum ids
   {
      a = 1,
      b = 2,
      c = 3,
      d = 30
   };

   char *names[50];
};

and the source file "test.cc" basically including

test::names[test::a] = "yum yum";
test::names[test::c] = "pum pum";
// ...

Wouldn't it make sense to wrap an implementation inside a namespace?

I would say that this would be because it is after the implementation of the header file, so it would be advisable to include the implementation in the same namespace as the header, without manually prefixing each variable with test::and without prefixing when using values ​​from the outside.

This is the opinion of a C ++ newbie, what could more intelligent people say here?

+3
source share
2 answers

test.cc. , - :

#include "test.h"

namespace test
{
    ...
    names[a] = "yum yum"; 
    names[c] = "pum pum"; 
    ...
}

using, :

#include "test.h"

using test;

...
names[a] = "yum yum"; 
names[c] = "pum pum"; 
...

.

+4

, , , , . , .

:

namespace test
{
    names[a] = "yum yum"; 
    names[c] = "pum pum"; 
}

, , , "" .

+2

Source: https://habr.com/ru/post/1764381/


All Articles