// ============================================================================ // p1c03_43 — 3.14.2.1 函数重载基本语法 // 来源:川大 C++/LinuxC wiki「02.Qt方向」 // 说明:本文件由 gen_part1.py 合并页面中的教学片段而成。每个片段用 // // --- 原文片段 [pageId:blockIdx] --- 标注出处。 // 已做最小修正(笔误/平台移植),详见 docs/ERRATA.md。 // ============================================================================ #include using namespace std; // --- 原文片段 [58954439:42] 3.14.2.1 函数重载基本语法 --- void MyFunc(string b){ cout << "b: " << b << endl; } //函数重载碰上默认参数 void MyFunc(string b, int a = 10){ cout << "a: " << a << " b:" << b << endl; } int main(){ // MyFunc("hello"); // 二义:MyFunc(string) 与 MyFunc(string,int=10) 同等匹配 // MyFunc(string("hello")); // 仍二义:强转 string 也无法区分两候选 MyFunc("hello", 20); // 显式给第二参 → 明确选双参重载 return 0; } // --- main ---