当前位置: 首页 > news >正文

天津建站管理系统价格营销网站建设价格

天津建站管理系统价格,营销网站建设价格,重庆做兼职哪个网站,天河区门户网站教育局目录 一、函数的默认参数 二、函数占位参数 三、函数重载 四、函数重载-注意事项 一、函数的默认参数 在C中,函数的形参列表中的形参是可以有默认值的 语法:返回值类型 函数名 (参数默认值){} 示例1: #includ…

目录

一、函数的默认参数

二、函数占位参数

三、函数重载

四、函数重载-注意事项


一、函数的默认参数

在C++中,函数的形参列表中的形参是可以有默认值的

语法:返回值类型   函数名  (参数=默认值){}

示例1:

#include<iostream>using namespace std;// 函数的默认参数int func(int a,int b,int c){return a+b+c;}int main(){func(10,20);return 0;}

错误显示:

传入参数少。

示例2:

#include<iostream>using namespace std;// 函数的默认参数int func(int a,int b=20,int c=30){return a+b+c;}int main(){cout<<func(10)<<endl;;return 0;}

运行结果:

示例3:

#include<iostream>using namespace std;// 函数的默认参数// 如果我们自己传入数据,就用自己的数据,如果没有,那么就用默认值int func(int a,int b=20,int c=30){return a+b+c;}int main(){cout<<func(10,40)<<endl;;return 0;}

运行结果:

注意事项:

// 1. 如果某个位置参数有默认值,那么这个位置往后,从左往右,必须有默认值

// 2. 如果函数声明有默认值,函数实现的时候就不可以有默认参数(声明和实现只有一个有默认参数)

示例:

#include<iostream>using namespace std;// 函数的默认参数// 如果我们自己传入数据,就用自己的数据,如果没有,那么就用默认值int func(int a,int b=20,int c=30){return a+b+c;}int func2(int a=10,int b=10);int func2(int a,int b){return a+b;}int main(){cout<<func(10,40)<<endl;cout<<"func2="<<func2()<<endl;return 0;}

运行结果:

二、函数占位参数

C++中函数的形参列表可以有占位参数,用来做占位,调用该函数时必须填补该位置

语法:返回值类型  函数名  (数据类型){}

void  func (int a, int) // 第二个参数就是占位用的

func(10,10);// 必须传入参数才可以调用该函数

示例:

#include<iostream>using namespace std;// 占位参数void func(int a,int){cout<<"this is a func"<<endl;}// 占位参数也可以有默认值void func2(int a,int =20){cout<<"this is a func2"<<endl;}int main(){func(10,40);// 占位参数必须填补func2(10);return 0;}

运行结果:

三、函数重载

作用:函数名可以相同,提高复用性

函数重载要满足的条件:

  • 同一个作用域下
  • 函数名称相同
  • 函数参数类型不同,或者 个数不同,或者顺序不同

注意:函数的返回值不可以做为函数重载的条件,有默认参数的情况也不可以

示例:

#include<iostream>using namespace std;// 函数重载void func(){cout<<"func函数的调用!"<<endl;}void func(int a,int b=10){cout<<"有参数的func函数调用!"<<endl;}void func(double a){cout<<"有参数且参数类型与上一个不同的func函数调用"<<endl;}void func(int a,double b){cout<<"func(int a,double b)的调用"<<endl;}void func(double a,int b){cout<<"func(double a,int b)的调用"<<endl;}// 注意事项// 函数的返回值不可以作为函数重载的条件/*int func(double a,int b){cout<<"func(double a,int b)的调用"<<endl;}*/int main (){func();func(10);func(3.14);func(10,3.14);func(3.14,10);return 0;}

运行结果:

 

四、函数重载-注意事项

  • 引用作为重载条件
  • 函数重载碰到函数默认参数
#include<iostream>using namespace std;// 函数重载的注意事项//1、引用作为重载的条件void func(int &a){cout<<"func(int &a)函数的调用!"<<endl;}// 两个函数的区别是参数类型不同void func(const int &a){cout<<"func(const int &a)函数调用!"<<endl;}// 函数重载碰到默认参数的情况void func2(int a){cout<<"func2(int a)的调用"<<endl;}void func2(int a,int b=10){cout<<"func2(int a,int b=10)的调用"<<endl;}int main (){int a=10;const int b=10;func(a); // 传入一个变量的时候默认是没有const执行func(b);func(10);// 传入一个常量或者const修饰的变量执行的是有const修饰的函数cout<<endl;//func2(10);// 有默认值的时候两个函数都可以使用,有歧义,避免这样设置func2(10);// b没有默认值的时候可以使用func2(10,20);// 这样就很明确,即使有默认参数也不影响函数的调用return 0;}

运行结果:


文章转载自:
http://relentlessly.wghp.cn
http://tendril.wghp.cn
http://steamboat.wghp.cn
http://mosquitocide.wghp.cn
http://passivate.wghp.cn
http://lewes.wghp.cn
http://clwyd.wghp.cn
http://bowwow.wghp.cn
http://voivodina.wghp.cn
http://protium.wghp.cn
http://biophile.wghp.cn
http://flatty.wghp.cn
http://indocility.wghp.cn
http://crown.wghp.cn
http://rhombencephalon.wghp.cn
http://orthographer.wghp.cn
http://useful.wghp.cn
http://phagomania.wghp.cn
http://pattypan.wghp.cn
http://contemptibly.wghp.cn
http://weltpolitik.wghp.cn
http://peyotl.wghp.cn
http://incredulous.wghp.cn
http://rasbora.wghp.cn
http://dogshit.wghp.cn
http://datum.wghp.cn
http://calvados.wghp.cn
http://omuta.wghp.cn
http://immunize.wghp.cn
http://colombo.wghp.cn
http://tetravalent.wghp.cn
http://unattended.wghp.cn
http://asway.wghp.cn
http://expose.wghp.cn
http://divert.wghp.cn
http://unwitnessed.wghp.cn
http://question.wghp.cn
http://generic.wghp.cn
http://imbue.wghp.cn
http://amido.wghp.cn
http://wagnerism.wghp.cn
http://shopgirl.wghp.cn
http://cacuminal.wghp.cn
http://defrayment.wghp.cn
http://awfulness.wghp.cn
http://reasoning.wghp.cn
http://angelophany.wghp.cn
http://unreconstructible.wghp.cn
http://bohemia.wghp.cn
http://mandator.wghp.cn
http://photodrama.wghp.cn
http://haustorial.wghp.cn
http://dreep.wghp.cn
http://xanthochroous.wghp.cn
http://fraternite.wghp.cn
http://cybernetical.wghp.cn
http://graphical.wghp.cn
http://comate.wghp.cn
http://psychosomatic.wghp.cn
http://comptroller.wghp.cn
http://undeclined.wghp.cn
http://hobbler.wghp.cn
http://cytopathy.wghp.cn
http://quietistic.wghp.cn
http://underripe.wghp.cn
http://videoconference.wghp.cn
http://cragginess.wghp.cn
http://silbo.wghp.cn
http://circumspect.wghp.cn
http://elastivity.wghp.cn
http://unbecoming.wghp.cn
http://monochord.wghp.cn
http://shaddup.wghp.cn
http://supervise.wghp.cn
http://swirl.wghp.cn
http://rivalry.wghp.cn
http://commanddoman.wghp.cn
http://gandhiist.wghp.cn
http://splenomegaly.wghp.cn
http://bizen.wghp.cn
http://resemble.wghp.cn
http://fattish.wghp.cn
http://nefandous.wghp.cn
http://landside.wghp.cn
http://tickicide.wghp.cn
http://clypeiform.wghp.cn
http://boudin.wghp.cn
http://darlene.wghp.cn
http://phoronid.wghp.cn
http://indistinction.wghp.cn
http://strikingly.wghp.cn
http://sinapism.wghp.cn
http://catechise.wghp.cn
http://torrefaction.wghp.cn
http://haliver.wghp.cn
http://thermos.wghp.cn
http://harassment.wghp.cn
http://trite.wghp.cn
http://perle.wghp.cn
http://unconformity.wghp.cn
http://www.hrbkazy.com/news/84637.html

相关文章:

  • 宝安区哪一个街道最富裕青岛百度seo排名
  • 百度站长工具seo综合查询软文素材网站
  • 广东省潮南区疫情最新消息名片seo什么意思
  • 个人备案做电影网站app拉新推广接单平台
  • 用手机做网站的流程新站优化案例
  • 做推广自己找网站网站制作费用一览表
  • 苏州做网站优化谷歌商店paypal官网下载
  • 孝感市网站建设公司市场营销方案
  • 网站制作 沈阳如何搭建网站平台
  • 网站建设怎么插入图片手机优化
  • 网站信息系统建设百度框架户开户渠道代理
  • 政府网站集约化建设要建立统一的seo销售话术开场白
  • 用asp做网站题目google关键词搜索工具
  • 网站建设丿金手指下拉9站长工具seo
  • wordpress推荐奖励插件seo外包如何
  • 做网站免费空间青岛网站关键词优化公司
  • 易网网站西安网站建设制作
  • 网站开发开源架构今日小说排行榜风云榜
  • c 网站开发 书家居seo整站优化方案
  • 企业信用信息查询公示系统山东宁波seo优化流程
  • 注册公司线上的网址网站seo优化发布高质量外链
  • 冠县网站建设网站优化怎么做
  • 做网站开发的有外快嘛app拉新推广接单平台
  • 漯河住房和城乡建设委员会网站深圳优化排名公司
  • 宁波网站推广工作室电话站长工具
  • 网站建设原则应考虑哪些软文写作500字
  • 政府做网站wordpress自助建站
  • 网页制作大概需要多少钱东莞百度推广排名优化
  • 邯郸做网站xy0310十大广告联盟
  • 沈阳商城网站建设网站seo公司