4 ms·
The reason is header files. If you do `using namespace std::something` in one file and it gets included in another, the other file now has std::something in the
by cmovq 4y ago
The reason is header files. If you do `using namespace std::something` in one file and it gets included in another, the other file now has std::something in the global namespace which it may not have excepted.
Other languages like Java have imports scoped a to a single file, so this is not a problem.
- jeroenhd 4y agoI see, but that's only a program in header files, isn't it? Most code will end up in .cpp files which don't get included (usually). It makes sense to use std::vector in a .h(pp) file, but in the .cpp you should be able to `using namespace std`, right?
- titzer 4y agoThe word "antiquated" comes to mind, but it's worse than that. An age-old self-created fractal hell of dumb problems created by a simplistic view of code reuse based on the simple mechanism of text inclusion that constantly restrains future evolution. It's antediluvian and just plain backwards.
- twic 4y agoWe are at least getting modules real soon now: https://en.cppreference.com/w/cpp/language/modules https://en.cppreference.com/w/cpp/language/modules
- xigoi 4y agoWe've been getting them real soon for… about 5 years now?
- ninkendo 4y agoThey were supposed to be part of C++11, back when it was called C++0x, before getting punted. So more like almost 20 years now (since some time after C++03.)
- duped 4y agoThe only compiler that seems to care about implementing modules is MSVC. It'll be "real soon" when GCC stops crashing.
- mardifoufs 4y agoI think there's a GCC branch that implements module, and it seemed pretty stable. But there must be a reason why it's not merged yet so you're most likely right.
- tragomaskhalos 4y agoUsing in a header file => complete no-no. Using in a cpp file => absolutely fine.
- jcelerier 4y ago> Using in a cpp file => absolutely fine. definitely not as soon as you want to do unity/jumbo builds (which are in my experience the n°1 thing to do to get fast CI builds)
- lenkite 4y agoIt should be completely fine to use `using namespace std` inside a function body right ?