C++ requires that all names must be unique. To avoid name clashes you place names inside namespaces:
- int x;
-
-
namespace system
-
{
-
struct data
-
{
-
int a,b,c;
-
datat x;
-
}
-
namespace mystuff
-
{
-
double x;
-
}
-
These are three different variables with names of:
::x
system::x
mystuff::x
So far so good. Now let’s say you don’t like all this :: stuff in the variable name so you can tell the compiler to check a namespace for the variable name:
Now instead of coding system::x all you need is x because you have told the compiler you are using namespace system.
However, this x might be ::x or system::x. If the x is ::x this code compiles. If the x is system::x, the code does not compile.
The using directive is for lazy programmers only. Top be safe you should always use fully qualified names in your