若把自定义函数中没有默认值的参数放在右边,如下
#include<bits/stdc++.h>
using namespace std;
double V(int length = 1,int width = 1, int height)
{
return length * width * height;
}
int main()
{
int length,width,height;
cin>>length>>width>>height;
cout<<V(1)<<endl;
cout<<V(length,width,height)<<endl;
}
则会报错
[Error] default argument missing for parameter 3 of 'double V(int, int, int)'
所以记住:无默认值的参数只能放左边:
#include<bits/stdc++.h>
using namespace std;
double V(int length,int width = 1, int height = 1)
{
return length * width * height;
}
int main()
{
int length,width,height;
cin>>length>>width>>height;
cout<<V(1)<<endl;
cout<<V(length,width,height)<<endl;
}