namespace MyNamespace
{
static void foo1()
{
}
}
using namespace MyNamespace;
class MyClass
{
void foo2()
{
::foo1();
}
};
The scope resolution operation ::
means using method in the global namespace. Here we can use ::foo1()
. This means method foo1()
is in the global namespace, am I right?
My question is, does using namespace ANAMESPACE_NAME
mean we import all elements form the namespace ANAMESPACE_NAME
into the global namespace?
No. "using namespace ANAMESPACE_NAME" mean we import all elements into current scope.
You can write something like this:
namespace A {
int i = 10, j = 20;
}
int f()
{
using namespace A; // injects names from A into the global scope.
return i * j; // uses i and j from namespace A.
}
int k = i * j; // Error: undefined variant i and j.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With