默认参数只在说明中给出!!!
#include <iostream>
using namespace std;
void f(int x, int a= 3, float b = 1.1);
int main() {
f(0);
return 0;
} ///:~
void f(int x, int a= 3, float b= 1.1)
/*
error C2572: 'f' : redefinition of default parameter : parameter 3
E:\vc++\MSDev98\Bin\45.cpp(4) : see declaration of 'f'
*/
{
cout <<a<<b;
}
</pre><pre name="code" class="cpp">/*
</pre><pre code_snippet_id="640820" snippet_file_name="blog_20150410_2_2994050" name="code" class="cpp">ok
#include <iostream>
using namespace std;
void f(int x, int = 3, float = 1.1);
int main() {
f(0);
return 0;
} ///:~
void f(int x, int a, float b)
{
cout <<a<<b;
}
#include <iostream>
using namespace std;
void f(int x, int = 3, float = 1.1);
int main() {
f(0);
return 0;
} ///:~
void f(int x, int a, float b)
{
cout <<a<<b;
}*/