C++ use symbols from other namespace without making them externally accessible -


is there construction similar using namespace doesn't make imported symbols visible outside body (or bodies) of namespace?

in example here, every symbol in whatever , other_namespace accessible through foo::<name_of_symbol> ... , i'd way prevent happening.

namespace foo {   using namespace whatever;   using namespace other_namespace;   // definitions } 

as complete example, program valid. if alternative using namespace intended semantics exists , used, not be.

namespace {   int func(int x) {     return 10;   } }  namespace b {   using namespace a; }  namespace c {   int do_thing(int x) {     return b::func(57);   } } 

you can use alias inside unnamed namespace.

namespace a_long_namespace_name {     void somefunc() {}; }  namespace b {     namespace { // unnamed namespace         namespace = a_long_namespace_name; // create short alias     }      void someotherfunc() {         a::somefunc();     } }  b::a::somefunc(); // compiler error 

you still need writing namespace call function, makes calls way shorter.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -