You are never required to put any declarations whatsoever in your own namespace.
It is good practice, in a large project, to put every declaration in a namespace. Maybe you have one namespace,
maybe two, maybe many. That's up to name. Namespaces were created to avoid name collisions between
two or more independent libraries. For example, you might download someone's libfoo and someone else's
libbar, but when you go to link both of them into your executable, you get duplicate definition errors because
both libraries had the function
void init_frobnicator();
.
So the answer to 1 is yes... it is meant to avoid symbol collisions.
I'm not sure about 2. Certainly you never need to create your own namespace. I'm not sure if it is necessary
to extend the std namespace to satisfy certain lookup rules. But I can say that it doesn't make sense to have
operators in a namespace. For example, I don't know what it means to declare
1 2
|
Rational operator+( Rational lhs,
Rational rhs )
|
in namespace rat. Does that mean in order to write r1 + r2 (both being of type Rational) I
have to use the namespace?
The answer to 3 is no.