What I meant was that a walkaround is to put these functions
and classes inside the class C and make them private. This
way make these functions and classes inaccessible by others,
but it also make it difficult to test them because you can not
access them from outside the class C.
So which is it: should they be accessible from outside the class
C, or not?
Therefore, this is not an viable option to restrict the access
of these class and functions. That is why I raised the
question whether there could be a 'private' keyword in
'namespace'.
And as I have pointed out, even if you could declare something
"private" in a namespace, it wouldn't change anything.
Your approach would work, but it is not convenient. Suppose
you construct a namespace N_private for the functions and
classes that are not for public access. To access a function
or class in N_private from N, you have to use the qualifier
N_private::.
Or in your implementation code (but not in the header), "using
namespace N_private;".
From experience, I can assure you that it's not really a
problem. I have one case where the class in question is a
template, which means that its implementation code is also in a
header, so I can't use "using namespace". And even most of the
time when I can, I don't (or else just in one or two functions).
Adding 'private' in 'namespace' would make refactoring easier.
How? That's what you've failed to show. As far as I can see,
private in a namespace would be completely meaningless.
Before you do code refactoring, you may not know what code
should be private.
What kind of silliness is that? At any point in time, you do
know (or you should) what should be private, and what shouldn't
be. (Of course, that can change in time; you might find in time
that it is useful to make some private function public, even to
the extent of locking you into a specific implementation. While
not a question of private/public, per se, see the recent
evolution of std::string for a good example of this.)
At any rate, the *only* evolution along these lines I've ever
seen is from private to public, not the other way around.
Therefore, you tend to put all of them in
the same namespace N. After refactoring, you may find some
classes or functions can be made 'private'. When there is no
such keyword 'private', you need to cut all the classes and
functions that you want to make private and paste them to the
namespace N_private. You then have to prepend all the
references of these functions and classes in N with
'N_private::'. But if you have such keyword 'private', it
would be much easier, you just need to add 'private' to the
declaration of the function and classes.
You're avoiding the basic question: what does it mean to make
something private in a namespace. Nothing, as far as I can see.
And as I said, in a class, the evolution is in the opposite
sense: the public parts are your constraining contract, and you
start with them as small as possible, only opening things up
when experience shows that 1) the actual implementation works,
so you won't have to change it, and 2) some client code can
possibly take advantage of it.
Your approach is also not safe. You can not prevent anybody
from accessing functions or classes in N_private delibrately.
And? What does private in a namespace do that this doesn't?