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
2009-12-23 12:04:55
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
2010-07-07 22:32:56
There are many, many differences between classes and namespaces.
anon
2010-07-08 07:57:20