C++: Namespaces — How to use in header and source files correctly?
问题 Consider a pair of two source files: an interface declaration file ( *.h or *.hpp ) and its implementation file ( *.cpp ). Let the *.h file be like the following: namespace MyNamespace { class MyClass { public: int foo(); }; } I have seen two different practices for using namespaces in source files: *.cpp showing practice #1: #include "MyClass.h" using namespace MyNamespace; int MyClass::foo() { ... } *.cpp showing practice #2: #include "MyClass.h" namespace MyNamespace { int MyClass::foo() {