设计函数dog(),输出狗的名字、高和长。默认狗的名字为tom,0.8米高,1.1米长。
#include<iostream>
#include<string>
using namespace std;
string name = "tom";
double h = 0.8, len = 1.1;
void dog(string dogname = name, double high = h, double lenth = len) {
cout << "Dogname:" << dogname << "\tHigh:" << h << "\tLenth:" << len << endl;
}
int main() {
name = "Jake";//修改全局变量,改变默认实参值
double h = 2.1;//h隐藏了全局变量h,对dog参数h的默认值无影响
dog();
return 0;
}