首页 > 编程语言 > 详细

c++默认参数

时间:2015-04-10 22:05:30      阅读:272      评论:0      收藏:0      [点我收藏+]
#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)
/*
<span style="font-size:24px;color:#ff0000;">error C2572: 'f' : redefinition of default parameter : parameter 3
        E:\vc++\MSDev98\Bin\45.cpp(4) : see declaration of 'f'</span>
  */
{
    cout <<a<<b;
}

/*
<span style="color:#ff0000;">//<span style="font-size:32px;">ok</span></span>
#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);
<span style="white-space:pre">	</span>return 0;
} ///:~


void f(int x, int a, float b)


{
    cout <<a<<b;
}<span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;">*/</span>

c++默认参数

原文:http://blog.csdn.net/h1023417614/article/details/44985173

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!