// namespace-main-17-18.cpp By: Aiman Hanna - ©1993-2006 Aiman Hanna // This program illustrates more on namespaces aliases. It is similar to // namespace-main-9-10.cpp. In specific the program illustrates the behavior // when the alias has the same name as the namespace and when the alias has // the exact name as another namespace. // Key points: 1) Namespace aliases - redefining a namespace #include "namespace18.h" int main() { // give an alias that is exactly the same as the namespase name namespace region3 = region3; // rg4 is an alias for region4 namespace rg4 = region4; // Now redefine region4 namespace region4 = region3::region31; namespace rg32 = region3::region31::region32; region3::Greeting(); region3::Calc1 c1(30), c11(45), c12(900); c1.setValue(32); rg4::Calc2 c2; c2.setValue(c1); cout << "The value of object \"c2\" has been set to : " << c2.getValue() << endl; // use the global object - set it to the same value as c1 rg4::dup.setValue(c1); cout << "The value of object \"dup\" has been set to : " << rg4::dup.getValue() << endl; region3::dup(c1, c11); cout << "The value of object \"c1\" has been set to : " << c1.getValue() << endl; cout << "\n\n==============================================\n"; region4::message1(); rg32::message2(); // rg33 alias was given in namespace18.h rg33::message3(); cout << "==============================================\n"; // rg4 will still behave as the original region4 rg4::dup.setValue(c12); cout << "The value of object \"dup\" has been set to : " << rg4::dup.getValue() << endl; return 0; } // The result of running the program /* Hello from region 3. The value of object "c2" has been set to : 32 The value of object "dup" has been set to : 32 The value of object "c1" has been set to : 45 ============================================== Hello...there...Is that really much better? ============================================== The value of object "dup" has been set to : 900 */