namespaces are tp prevent collisions when yu use names that are the same as someone else's. All names need to be unique.
Suppose you have a variable called cout. That would conflict with the cout that's part of C++ so you put your variable in a namespace:
- namespace MyStuff
-
{
-
int cout;
-
}
Now you can code:
and still use the C++ cout:
- std::cout << MyStuff::cout << std::endl;
The preferred technique is to precede each variable with it's namespace as above.
The next worst thing to do is put a "using" declaration at the beginning of each function. But that may not resolve collisions within that function.
The next worst thing to do is to place a "using" declaration at the beginning of the file since that would permit collisions to all functions in that file.
And the biggest no-no of all is to put the "using" declaration in a header file that is included all over the place. That would permit collisions in all of your code.