#include #include using namespace std; int fun() { return 2; } namespace Foo { int foo; int bar; int foofun() { return 1; } } namespace Test { using namespace Foo; using Foo::bar; // after this declaration, there is a Test::bar variable int fun() { foo = 10; return 1; } int fun1(int); } int Test::fun1(int x) { return x; } using namespace Test; // after this directive, you // can use names defined in global, std and Test // (does include Test::hello defined later), // no search priority is given, can not // have name collision namespace Test { int hello() { return 10; } } int j; namespace M { int i; int j; } namespace N { int i; using namespace M; // the names in namespace M is introduced // to the following as the same scope // as global scope // using M::i; // multiple declaration of i; int nfun() { // j = 20; // ambiguous, name conflict i = 10; return i; } } using namespace N; // this would cause i to be an ambigious symbol void main() { vector array; int i; // no collision, using scope rule to resolve for (i=0; i<10; i++) array.push_back(i); for (i=0; i