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

前端 未结 5 1469
走了就别回头了
走了就别回头了 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:03

    From a code readability standpoint, it is probably better in my opinion to use the #2 method for this reason:

    You can be using multiple namespaces at a time, and any object or function written below that line can belong to any of those namespaces (barring naming conflicts). Wrapping the whole file in a namespace block is more explicit, and allows you to declare new functions and variables that belong to that namespace within the .cpp file as well

提交回复
热议问题