// ============================================================================ // p1c03_11 — 3.2.3 using声明 // 来源:川大 C++/LinuxC wiki「02.Qt方向」 // 说明:本文件由 gen_part1.py 合并页面中的教学片段而成。每个片段用 // // --- 原文片段 [pageId:blockIdx] --- 标注出处。 // 已做最小修正(笔误/平台移植),详见 docs/ERRATA.md。 // ============================================================================ #include using namespace std; // --- 原文片段 [58954439:10] 3.2.3 using声明 --- namespace A{ int paramA = 20; int paramB = 30; void funcA(){ cout << "hello funcA" << endl; } void funcB(){ cout << "hello funcA" << endl; } } void test(){ //1. 通过命名空间域运算符 cout << A::paramA << endl; A::funcA(); //2. using声明 using A::paramA; using A::funcA; cout << paramA << endl; //cout << paramB << endl; //不可直接访问 funcA(); //3. 同名冲突 //int paramA = 20; //相同作用域注意同名冲突 } // --- main --- int main() { test(); return 0; }