Search code examples
c++namespaceslinkage

What is the impact of namespaces in c++ linkages compared to linkages in c?


What is the impact of namespaces in c++ linkages compared to linkages in c?

Is it possible to make a name that has internal linkage to external linkage just by using namespace.Similarly the other way around.


Solution

  • In general, namespace name is prepended to any enclosed entity's name before the name is mangled and goes to the linker.

    If you have two functions with the same signatures in different namespaces they link into one file just fine. If you have two classes with the same name and at least one method with the same signature and these classes are in different namespaces – they again link together just fine.