I come from a Java background, where packages are used, not namespaces. I’m used to putting classes that work together to form a complete object into packages, and then reusing them later from that package. But now I’m working in C++.
How do you use namespaces in C++? Do you create a single namespace for the entire application, or do you create namespaces for the major components? If so, how do you create objects from classes in other namespaces?
Namespaces are packages essentially. They can be used like this:
Then in code:
Or, if you want to always use a specific namespace, you can do this:
Edit: Following what bernhardrusch has said, I tend not to use the ‘using namespace x’ syntax at all, I usually explicitly specify the namespace when instantiating my objects (i.e. the first example I showed).
And as you asked below, you can use as many namespaces as you like.