0

I have read a lot about avoiding the usage of using namespace due to the possibility of conflicting calls from different libraries.

So my question is whether or not this problem remains if I use only 1 such using namespace in my header, but I use more than 1 library? In other words are there any problems other than conflicting library calls.

Celahir
  • 1
  • 1
  • 1
    No, still a bad idea regardless. Make sure to read https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice thoroughly. – cigien Aug 14 '20 at 15:07
  • 1
    If there was an absolute "never do this with using namespace" it would be : "Don't put them in headers" – Jeffrey Aug 14 '20 at 15:09
  • 1
    There is no difference if u used it once or more. Does this answer your question? [Why is "using namespace std;" considered bad practice?](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) – asmmo Aug 14 '20 at 15:10
  • 1
    *Never* use `using namespace` in a header. It *can* be ok in a source file (although I'd personally avoid it - at least at file scope), but it is *never* a good idea in a header. – Jesper Juhl Aug 14 '20 at 15:13
  • 2
    Headers are copied and pasted into a file when they are included. If you employ the directive in a header, it won't just be "once". It will be everywhere that header is included. And it's not like the problems you are warned against happen only if you do it many times. Even once is enough. Oh, and if you are `using namespace std;` in a header, and it's part of a project many people work on, prepare yourself for some very unpleasant conversations. – StoryTeller - Unslander Monica Aug 14 '20 at 15:14
  • 1
    You can get away with it only if it's inside of *another* namespace. – Mark Ransom Aug 14 '20 at 15:19
  • @François Andrieux No, I genuinely didn't know how this works. Thank you all for clearing up my misunderstanding. – Celahir Aug 14 '20 at 15:20

0 Answers0