views:

201

answers:

2

Is it possible to make a namespace friend of a class, say I have a unit test namespace with many classes and I wanted the test namespace to be friend to a class so that it has access to private implementation details.

A: 

If you are using .NET, you may want to take a look at the InternalsVisibleTo attribute. Anyway note that this works for whole assemblies, not for single namespaces.

Konamiman
+1  A: 

No, this is not possible in C++. Frankly, it smacks of poor design.

anon
Why do you say it is bad design? I think it could possibly be done and be usefull. There is not much difference between a class and namespace except the this pointer. I don't see why the friend declaration couldn't work for a namespace, allowing it's member function to be able to access implementation details of a class. This could allow non-member functions related to a class easy access to that class' internals. Basically how would you do it right now? Use a class declaration when a namespace would suffice and friend that class? friend every function that need access to the class?
n1ck
There are many, many differences between classes and namespaces.
anon