// ============================================================================ // p1c03_13 — 3.2.4 using编译指令 // 来源:川大 C++/LinuxC wiki「02.Qt方向」 // 说明:本文件由 gen_part1.py 合并页面中的教学片段而成。每个片段用 // // --- 原文片段 [pageId:blockIdx] --- 标注出处。 // 已做最小修正(笔误/平台移植),详见 docs/ERRATA.md。 // ============================================================================ #include using namespace std; // --- 原文片段 [58954439:12] 3.2.4 using编译指令 --- namespace A{ int paramA = 20; int paramB = 30; void funcA(){ cout << "hello funcA" << endl; } void funcB(){ cout << "hello funcB" << endl; } } void test01(){ using namespace A; cout << paramA << endl; cout << paramB << endl; funcA(); funcB(); //不会产生二义性 int paramA = 30; cout << paramA << endl; } namespace B{ int paramA = 20; int paramB = 30; void funcA(){ cout << "hello funcA" << endl; } void funcB(){ cout << "hello funcB" << endl; } } void test02(){ using namespace A; using namespace B; //二义性产生,不知道调用A还是B的paramA //cout << paramA << endl; } // --- main --- int main() { test01(); test02(); return 0; }