We usually use namespaces to avoid name clashes in C++. But what if there are two different libraries which have a class, that has the same namespace name and class name? Is there a work around?
(PS: I am pretty sure, that its a rare scenario, I never faced it, just happened to cross my mind)
It might happen, but its not very likely to do you much damage. Not only do the namespace names have to be exactly the same, you have to actually use both libraries. Chances are, if they’ve named their namespaces in some reasonable way, their names will indicate their purpose — even if there are two libraries that use
GenericXMLParseras their namespace, and probably have some class names in common, do you really expect to be using them both on one project?This does make certain namespace names a bad idea, such as
boostorOgre. Anyone using those (except the original users) should expect their library to be unusable in many cases. A less common name, likePie, is probably going to be fine for by far most people in by far most cases. If both libraries usingPiebecome widely used, one might have to change; in that case, the namespace renaming trick can be used to keep backwards compatibility with old code.