I read somewhere that Jhon worked in company A with Id 102 and Jhon worked in company B with Id 102 now these r two different persons recognised by the different companies they worked .now if they worked in the same company it is impossible to differentiate them.Likewise,to avoid this problem namespaces r used in C++.Please take an object and explain y a namespace is necessary for it
The namespace is like the company, having different namespace (eg namespace A and namespace B) you can have something which has the same name (eg: Jhon) and even the same Id but they are different.
1 2 3 4 5 6 7 8
namespace A
{
int Jhon;
}
namespace B
{
int Jhon;
}
Both A::Jhon and B::Jhon are integers so without namespaces would be impossible to distinguish them