When it comes to using namespaces
it is really good thing to avoid name clashes. But the thing that matters me: Using anonymous namespaces
.
Here in my example for some reason I defined two un-named namespaces and accidently the two has a member function with the same signature. And I want to define the two outside the namespaces.
namespace {
void foo(); // to be defined outside in somewhere else
int x = 0; // I want the above foo() to increment x
}
namespace {
void foo(); // to be defined outside in somewhere else
// I want foo to do something else
}
// Here is my guess how to define a function outside Anonymous NS.
void ::foo() {
cout << "::foo()" << endl;
}
// void foo(){
// cout << "foo()" << endl;
//}
int main(){
foo();
::foo();
cout << endl;
cin.get();
return 0;
}
- How to avoid name clashes when having multiple Un-Named-Namespaces?
Thank you.