123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- #include <iostream>
- using namespace std;
- #if 0
- int a = 10;
- void test01()
- {
- int a = 20;
- cout << "局部变量a = " << a << endl;
-
- cout << "全局变量a = " << ::a << endl;
- }
- namespace A {
- int a = 100;
- }
- namespace B {
- int a = 200;
- }
- void test02()
- {
-
- cout << "namespace A中的a = " << A::a << endl;
- cout << "namespace B中的a = " << B::a << endl;
- }
- namespace A {
- int a = 1000;
- namespace B {
- int a = 2000;
- }
- }
- void test03()
- {
- cout << "A中的a = " << A::a << endl;
- cout << "B中的a = " << A::B::a << endl;
- }
- namespace A{
- int a = 100;
- int b = 200;
- }
- namespace A{
- int c = 300;
- }
- void test04()
- {
- cout << "A中的c = " << A::c << endl;
- }
- namespace A{
- int a = 100;
- void func()
- {
- cout << "func遍历a = " <<a<<endl;
- }
- }
- void test05()
- {
-
- cout << "A中的a = " << A::a << endl;
-
- A::func();
- }
- namespace A{
- int a = 100;
- void func();
- }
- void A::func()
- {
- cout << "func遍历a = " << a << endl;
- }
- void funb()
- {
- cout << "funb遍历a = " << A::a << endl;
- }
- void test06()
- {
- A::func();
- funb();
- }
- #endif
- namespace veryLongName{
- int a = 10;
- void func()
- {
- cout << "hello namespace" << endl;
- }
- }
- void test()
- {
- namespace shortName = veryLongName;
- cout << "veryLongName::a : " << shortName::a << endl;
- veryLongName::func();
- shortName::func();
- }
- int main()
- {
- test();
- return 0;
- }
|