码迷,mamicode.com
首页 > 编程语言 > 详细

c++默认参数

时间:2015-04-10 22:05:36      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:c++

#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++默认参数

标签:c++

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!