博客
关于我
函数的默认参数值,即在定义参数的时候给它一个默认值
阅读量:306 次
发布时间:2019-03-04

本文共 728 字,大约阅读时间需要 2 分钟。

 

int add(int a,int b=2,int c =4);
  • 1

其中有两个规定

1.如果某个参数是默认参数,那么它后面的参数必须是默认参数

2.默认参数可以放在声明、或者定义中,但是只能二者选一

以上是网上看的一个帖子:但是自己ubuntu18.04,g++编译的时候,必须把默认形参放在声明中,

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;void biggies(vector
& words,vector
::size_type sz,ostream & os=cout , //;默认形参char c = ' ' );                     //默认形参int main(){ vector
vstr{"1","2","33","444","555","6666","77777","88888","89999","00000"}; biggies(vstr,100); return 0;}void biggies(vector
&words,vector
::size_type sz,ostream &os,char c){ for_each(words.begin(),words.end(),[&os,c](const string &s){os << s << c;});}

 

转载地址:http://dgpq.baihongyu.com/

你可能感兴趣的文章
windows程序设计(4):文本输出
查看>>
21.2.3总结
查看>>
线性代数和数学期望杂题
查看>>
【SSL_P2876】2017年东莞市信息学特长生测试题 工程
查看>>
【洛谷_P1433】吃奶酪
查看>>
赠书和投票 | 你知道中国有哪些Server SAN厂商吗? 投票:你心目最好的HCI品牌是?
查看>>
volatile关键字和AtomicInteger
查看>>
redisTemplate.opsForHash()
查看>>
maven生命周期
查看>>
方法的绑定机制-静态绑定和动态绑定
查看>>
setnx
查看>>
Java取绝对值
查看>>
线程的start()方法
查看>>
for循环读取数组遇问题:dexError: invalid index to scalar variable.
查看>>
编写测试用例的实用小技巧
查看>>
c语言贪吃蛇控制台版
查看>>
Windows10 下springboot应用无法被外部网络访问
查看>>
报错:在IDEA中springboot项目操作数据库,配置文件驱动com.mysql.cj.jdbc.Driver标红
查看>>
redis报错(error) NOAUTH Authentication required.解决办法
查看>>
【树形dp】P1273 有线电视网
查看>>