std::
, so why not use using namespace std;
?I think its easier to use than to repeat std:: through the entire code.jsmith wrote: |
---|
You should also understand why namespaces were added to the language in the first place, because a "using namespace std;" in a .cpp file defeats the purpose of namespaces in that .cpp file. Namespaces were added to avoid global name conflicts. For example, you might be using two libraries, both of which define a class called "List". If those declarations are not in a namespace, then you end up with ODR (one definition rule) violations that lead ultimately either to compile errors or unexpected runtime behavior. By putting the declarations in separate namespaces and referring to them with their fully qualified name, there is no ambiguity as to which one you mean. When you use blanket "using namespace" clauses, you potentially reintroduce those ambiguities. Having said all this, unless you are compiling against multiple external libraries or are working on an extremely large project, you _probably_ won't have any troubles by just writing "using namespace std;" in your .cpp files. |