C++: Namespaces — How to use in header and source files correctly?

前端 未结 5 1462
走了就别回头了
走了就别回头了 2021-01-30 00:42

Consider a pair of two source files: an interface declaration file (*.h or *.hpp) and its implementation file (*.cpp).

Let the

5条回答
  •  遥遥无期
    2021-01-30 01:21

    The clearest is the option you didn't show:

    int MyNamespace::MyClass::foo()
    {
        //  ...
    }
    

    It's also very verbose; too much so for most people. Since using namespace is a recepe for name conflicts, at least in my experience, and should be avoided except in very limited scopes and places, I generally use your #2.

提交回复
热议问题