In the first example, when you turn on
backtrace.h
in another file, this file will also use these names. Therefore, if by mistake someone wrote "blax" in the file where you included backtrace.h, and "blax" also turned out to be a class or function in your namespace, for example:
my_namespace1::component1::blax
the compiler can use its "blax" to mean "my_namespace1 :: component1 :: blax"
By placing the using namespace in another namespace, you simply include all these definitions in this namespace, in the previous example, if you went with the second version of the code, which will not collide because "my_namespace1 :: component1 :: blax" will be included as my_application :: platform_logs :: blax.
In general, most coding guides will help you: a) Prefer to never do "use namespaces" or at least use it only for shorthand (for example, using short_namespace = first_namespace :: another_namepsace :: last_namespace)
b) If you use "use namespace", do it in the source file (for example, ccp or .c files), since the definitions in these files are not included
c) If you use "use namespace" in headers, paste it into another namespace (for example, in your example) so that it does not "leak" into the scope of another file that includes your header
source share