How to work with a library that does not use namespaces

In my project, I have to use a library whose characters are not in the namespace. Library classes have fairly short and common names, such as Loggerand Reader. I also use some of these names in my own project classes.

Consider a situation where my project symbols are also not replaced by names. The name conflict can be resolved by putting my code in the namespace and distinguishing it with qualified names (for example, ::Loggerand My::Logger), but I would prefer names to be placed in library symbols. Is there a way that I can "force" use library characters in the namespace of my choice?

Secondly, what if I wanted to use two different libraries that defined non-namespaced Logger. Is there any way to avoid namespace conflict in this case?

+4
source share
2 answers

Is there any way to "force" the use of library characters in the namespace of my choice?

No, you cannot do this. The way I could imagine is to provide a wrapper API that actually uses namespaceand forth from different names, such as LoggerExt.

What if I wanted to use two different libraries that defined non-namespaced Logger?

You lost, at least the linker will tell you about it.

+5

4 , :

  • , . ( )
  • , , . ( ).
  • , . ( , , )
  • , , , , , . ( , , ).
0

Source: https://habr.com/ru/post/1629694/


All Articles