1

My code is including headers from some large open source projects. One of them is C and the other C++. Unfortunately, the C header declares structures that share the same name as C++ standard template library (std::) classes like map and list. I'm getting an "ambiguous symbol" error on those. It turns out that the C++ project has using namespace std; in some header files. I don't want to fork the packages and modify them if I can avoid it, as it would be a monumental task.

Is it possible instead to "turn off" the using namespace std inside my code, so it will not attempt to resolve list or map as possibly belonging to that namespace? See the code sample below and the needed not_using directive. I know not_using doesn't exist. I'm looking for a way to achieve that effect.

using namespace std;
map<string, string> mapOk; // compiles but conflicts with C symbol 

not_using namespace std;   // I need something like this because...
std::map<std::string, std::string> mapOk2; // I want to force the use of std:: to resolve
map<string, string> badMap;  // Causes compile error
Cosmo
  • 491
  • 7
  • 14
  • File a bug with that C++ project (with patch to clean it up). That's terrible practice. (Unless you're (ab)using some sort of internal headers of theirs.) – Mat Apr 09 '19 at 19:32
  • There is no getting the cat back into the bag once it is out. File an issue with the project and find a better one. – NathanOliver Apr 09 '19 at 19:32

0 Answers0