Format:
- namespace identifier
-
{
-
entities
-
}
The keyword
using is used to introduce a name from a namespace into the current declarative region.
Example:
- #include <iostream>
-
using namespace std;
-
-
namespace first
-
{
-
int x = 5;
-
int y = 10;
-
}
-
-
namespace second
-
{
-
double x = 3.1416;
-
double y = 2.7183;
-
}
-
-
int
-
main(void)
-
{
-
using first::x;
-
using second::y;
-
cout << x << endl;
-
cout << y << endl;
-
cout << first::y << endl;
-
cout << second::x << endl;
-
-
return (0);
-
}
We can declare alternate names for existing namespaces:
- namespace new_name = current_name;
阅读(925) | 评论(0) | 转发(0) |