One way found. I can encapsulate namespace inside another dummy type namespace and then use it. To avoid details, we can use an alias for an existing namespace .
i.e.
//Nh namespace DUMMY_ { // <--- put a dummy outer namespace namespace N { //... } } namespace N = DUMMY_::N; // alias the name to the original name //Other.h #include"Nh" namespace N { // <--- error !! void foo () {} }
Change With the above solution, it is less likely that people will extend namespace N However, as @Charles comment, still DUMMY_ displayed to the reader. This means that you can still:
namespace DUMMY_ { namespace N {
Thus, it remains only to prohibit unwanted expansion, replacing:
namespace N = DUMMY_::N;
with,
#define N DUMMY_::N
This will work as expected; but we enter the macro area.
source share