I have following code and I don't know how can I access the x inside the anonymous namespace in this setting. Please tell me how?
#include <iostream>
int x = 10;
namespace
{
int x = 20;
}
int main(int x, char* y[])
{
{
int x = 30; // most recently defined
std::cout << x << std::endl; // 30, local
std::cout << ::x << std::endl; // 10, global
// how can I access the x inside the anonymous namespace?
}
return 0;
}
You can't!
You cannot access the namespace's members by its name, because it doesn't have one.
It's anonymous.
You can only access those members by virtue of their having been pulled into scope already.
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