The C++ namespace: the namespace alias, giving new name for the original namespace C++ code sample

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C++

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)

Other info: none

To do: Printing some data to demonstrate how to give new name (alias) to the existing namespace in C++ programming

To show: How to give new name (alias) to the existing namespace in C++ programming

 

// namespace alias

#include <iostream>

using namespace std;

 

namespace TheFirstLongNamespaceSample

{

double p = 23.44;

 

namespace TheNestedFirstLongNamespaceSample

{

int q = 100;

}

}

 

// namespace alias

namespace First = TheFirstLongNamespaceSample;

 

// use access qualifier to alias a nested namespace

namespace Second = TheFirstLongNamespaceSample::TheNestedFirstLongNamespaceSample;

 

int main(void)

{

using namespace First;

using namespace Second;

 

cout<<"p = "<<p<<endl;

cout<<"q = "<<q<<endl;

 

return 0;

}

 

Output example:

 

p = 23.44

q = 100

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index