Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

namespace clash with two large libraries

I'm trying to use two very large C++ libraries to write my own library and application set and there are using directives present in the main header classes of both libraries. The conflict lies in a single class, called vector (with the std::vector). One header has "using namespace std", and this messes things up.

Is there a way to exclude the identifier from the namespace, after the "using namespace" has already been written?

like image 855
tmaric Avatar asked Jun 09 '26 12:06

tmaric


2 Answers

Is there a way to get the worms back into the can?

No.

The best option is to fix the header with the using directive. Remove it and add the required std:: prefixes to the declarations.

like image 195
Bo Persson Avatar answered Jun 11 '26 02:06

Bo Persson


There's no way to un-using in C++. In this case the only options I can think of are:

  • Have the library writers fix their library. using in a header is absolutely a bug in the library that should be fixed.

  • Completely isolate the two libraries from each other within your application by using separate, completely compartmentalized implementation files. If the two libraries would need to communicate you'd have to create some sort of mediator in your code to glue them together.

like image 23
Mark B Avatar answered Jun 11 '26 01:06

Mark B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!