All methods are correct, and each of them has its advantages and disadvantages.
In version 1, you have the advantage of not having to write a namespace before each function. The downside is that you get boring identification, especially if you have more than one level of namespace.
In version 2, you make your code cleaner, but if more than one namespace is implemented in CPP, you can directly access other functions and variables, which makes your namespace useless (for this cpp file).
In version 3, you will need to enter more, and your function lines may be larger than the screen, which is bad for design effects.
There is another way to use it by some people. This is similar to the first version, but without identification problems.
This is true:
#define OPEN_NS1 namespace ns1 { #define CLOSE_NS1 } OPEN_NS1 void MyClass::method() { ... } CLOSE_NS1
You decide which one is best for each situation =]
Renan Greinert Dec 30 '11 at 16:51 2011-12-30 16:51
source share