第五节 · 自助服务 · 默认实参与函数指针
void greet(string name = "朋友")
{
cout << "你好, " << name << "!" << endl;
}
int main()
{
greet("小明"); // 输出: 你好, 小明!
greet(); // 输出: 你好, 朋友!(使用默认值)
return 0;
}// 正确
void func1(int a, int b = 10, int c = 20);
// 错误!不能跳过中间的参数
void func2(int a = 10, int b, int c = 20); // 编译错误
// 正确
void func3(int a, int b, int c = 20);
// 正确
void func4(int a = 1, int b = 2, int c = 3);习题
Last updated