c++ - How can I explicitly refer to an enclosing namespace when an inline namespace exists? -


please consider code:

#include <iostream>  namespace foo{      void ool()  // version     {         std::cout << "foo::ool" << std::endl;     }      inline namespace bar{         void ool() // version b         {             std::cout << "foo::bar::ool" << std::endl;         }     } }   int main() {     foo::ool();  // <- error } 

both clang , g++ correctly mark foo::ool ambiguous. can call foo::bar::ool without problem there way call version without changing declaration?

i found people in similar position trying understand happens did not see solution case.

i in situation because have project includes declaration of std::__1::pair , std::pair, made in different places, std::__1 being inline namespace. need code point std::pair explicitly. there solution that?

i don't think possible; cppreference:

qualified name lookup examines enclosing namespace include names inline namespaces if same name present in enclosing namespace.

however, seems not in situation describe, 2 definitions pulled different files. "bookmark" more external definition in order able call when need it:

#include <iostream>  // equivalent of first include namespace foo{     void ool()  // version     {         std::cout << "foo::ool" << std::endl;     } }  const auto& foo_ool = foo::ool;  // equivalent of second include namespace foo{     inline namespace bar{         void ool() // version b         {             std::cout << "foo::bar::ool" << std::endl;         }     } }  int main() {     foo_ool(); // works } 

if thing want bookmark type, simple using directive should suffice. equivalent code like:

#include <my_first_include>  // bookmark code  #include <my_second_include>  // rest of code 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -