I am using a C++ third party library that places all of its classes in a versioned namespace, let’s call it tplib_v44. They also define a generic namespace alias:
namespace tplib = tplib_v44;
If a forward-declare a member of the library in my own .h file using the generic namespace…
namespace tplib { class SomeClassInTpLib; }
… I get compiler errors on the header in the third-party library (which is being included later in my .cpp implementation file):
error C2386: 'tplib' : a symbol with this name already exists in the current scope
If I use the version-specific namespace, then everything works fine, but then … what’s the point? What’s the best way to deal with this?
[EDIT] FYI for future viewers, this was the ICU library. A solution (at least in my situation) is in the comments to the accepted answer.
It looks like there is an ugly workaround for this, but no good solution.
For ACE (with a decent explanation) and Xerces (with a snarky “this is how c++ works” comment), they define macros that you can use to do this “generically”.
It looks like an unfortunate c++ artifact, try searching around in your
tplibfor these macros.The standard treats namespaces and namespace aliases as different things. You’re declaring
tplibas a namespace, so when the compiler tries to assign an alias later, it cannot be both, so the compiler complains.