namespace myprogram{ class myclass;}using namespace myprogram;int main(int argc, char *argv[]){ myclass myinstance;}
There isn''t much benefit to that other than that it gets you in the habit of doing it. You didn''t ask what you should do in your program though. You asked what they are and when/how they should be used. So you got stripped down examples. Certainly it would not make any sense to simply nest a bunch of namespaces to define one class. Generally I divide things up into groups of five to ten. So if the company had five systems and each system had five projects and each project created five libraries and each library had five classes that would be 625 classes. Across an entire company with an I/S staff of a few thousand you could easily get into tens of thousands of classes. Think Microsoft, not you dinking around on a computer at home.
What a namespace does is provide a context. So someone says ram. Do they mean random access memory, a male goat or running something into something else? You need a context. So perhaps you have Computer::RAM, Animal::Ram, Action::Ram. Now the possiblities are reduced considerably. Do you write programs in an environment where the most appropriate name for a class is the same as the most appropriate name for a differant class in a differant context? Apparently not. It doesn''t change what they are and when/how you should use them. It simply means you may have no need for them. Since it only takes four lines of code if you count the brackets I would argue you might as well use them even if you don''t need them. Then perhaps someday you will have an alternative to change a name used in a hundred programs. That alternative would be fully qualifying the name in the one program within which you actually have a problem.