c++ - Use of "using namespace" when declaring that namespace -
suppose have next files:
// someclass.h namespace illustration { class someclass { ... someclass somefunction(); ... }; } // someclass.cpp example::someclass example::someclass::somefunction() { ... }
would there consequences add together "using namespace example;" before namespace in someclass.h eliminate need of adding "example::" scope operator things in someclass.cpp file? if there no conesequences, considered bad coding practice?
the alter follows:
// someclass.h using namespace example; namespace illustration { class someclass { ... someclass somefunction(); ... }; } // someclass.cpp someclass someclass::somefunction() { ... }
no, please don't set using namespace ...;
in global area. can this:
someclass.h
// using namespace example; // never here please namespace illustration { using namespace otherexample; // okay (not global) class someclass { ... someclass somefunction(); ... }; }
someclass.cpp
namespace illustration // same in .h { using namespace otherexample; // okay (not global) someclass someclass::somefunction() { ... } }
and suggest potentially huge namespaces std::
never utilize using namespace std;
within own namespaces because drag in many mutual symbol names.
c++ namespaces coding-style
No comments:
Post a Comment