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

python 网站开发 普及消防证怎么考取需要什么条件

python 网站开发 普及,消防证怎么考取需要什么条件,公司注册公司需要什么资料,衡水建设公司网站3.1 函数默认参数 本节内容之前已经整理过,详见22.函数的默认值 3.2 函数占位参数 C中函数的形参列表里可以有占位参数,用来做占位,调用函数时必须补填该位置 语法: 返回值类型 函数名 (数据类型) {} 在现阶段函数的占位参数…

3.1 函数默认参数

本节内容之前已经整理过,详见22.函数的默认值

3.2 函数占位参数

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

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

在现阶段函数的占位参数存在意义不大,但是后面的课程中会用到该技术

示例:

#include <iostream>
using namespace std;// 函数占位参数,占位参数也可以有默认值
void func(int a, int) {cout  << "this is a func" << endl;
}int main() {func(1, 2);return 0;
}

3.3 函数重载-基本语法

作用:函数名可以相同,提高复用性
函数重载满足条件

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

注意:函数的返回值不可以作为函数重载的条件

示例:

#include <iostream>
#include <iostream>
using namespace std;// 1.参数类型不同
void print(int a)
{cout << "int" << endl;
}
void print(double a)
{cout << "double" << endl;
}// 2.参数顺序不同
void print(double a, int b) {cout << "int int" << endl;
}
void print(int a, double b) {cout << "double double" << endl;
}
// 注意:同类型参数顺序不同是不被允许的,因为函数名相同,编译器会认为这是同一个函数
// void print(int a, int b) {}和void print(int b, int a) {}同时出现时,编译器会报错// 3。参数个数不同
void print(int a, int b, int c) {cout << "int int int" << endl;
}
void print(int a, int b,  int c, int d) {cout << "int int" << endl;
}// 注意事项:函数返回值类型不同不可作为函数重载的条件
int main()
{print(1);print(1.0);print(1.0, 1);print(1, 1.0);print(1, 1, 1);print(1, 1, 1, 1);return 0;
}

3.4 函数重载-注意事项

  • 引用作为重载条件
  • 函数重载碰到函数默认参数

示例:

#include <iostream>
using namespace std;// 函数重载注意事项
// 1.引用作为重载的条件
void fun(int& a) {cout << "func(int& a)调用" << endl;
}void fun(const int& a) {cout << "func(const int& a)调用" << endl;
}// 2.函数重载碰到默认参数
void func(int a) {cout << "func(int a)调用" << endl;
}
void func(int a, int b = 10) {cout << "func(int a, int b = 10)调用" << endl;
}int main() {// func(int& a)调用int a = 10;fun(a);// func(const int& a)调用const int b = 10;fun(b);fun(10);// 当函数调用碰到默认参数会出现二义性报错// func(10);   // 错误❌,默认参数不能省略func(10,10);    //  正确return 0;
}
http://www.dtcms.com/a/491109.html

相关文章:

  • 网络层次划分-网络层
  • 做响应式网站应该注意什么问题有自己的域名怎么建设网站
  • ClickHouse 数据更新策略深度解析:突变操作与最佳实践
  • 餐饮商城网站建设网站备案幕布要求
  • Prometheus监控部署
  • php ajax网站开发典型实例 pdfwordpress账号邮箱
  • 栈与队列:数据结构的基石与应用
  • 多态的定义
  • 开设网站的费用在微信怎样搞做微视频网站
  • wordpress禁止游客访问上海市网站seo
  • AI代码生成对CRUD联调流程的重构分析
  • 如何通过优化中药饮片采购流程实现供应链协同?
  • 建站产品网页制作工作怎么样
  • python编程基础知识
  • 使用VSCode SSH插件实现免密码登录远程服务器
  • vscode浏览器启动报错
  • 网站设计制作新参考价格中国企业500强江阴有几家
  • 车载电子电器架构 —— 基于AP定义车载HPC
  • YOLO 目标检测算法:从 v1 到 v2 的技术演进与优化实践
  • Spring Boot 3零基础教程,Spring Boot 日志级别,笔记19
  • iOS混淆与IPA文件加固全流程实战 防止苹果应用被反编译的工程级方案
  • 济宁市网站建设新乡营销网站建设公司哪家好
  • 网站建设方案总结wordpress音频付费插件
  • 解决VMware Workstation Pro 17中Ubuntu 24.04无法复制粘贴
  • 上辽宁建设工程信息网站移动网站建设口碑好
  • 【力扣 SQL 50】聚合函数篇
  • 做网站如何用代码把字体变大云南定制化网站建设
  • 免费建立微信网站好看的wordpress工具
  • 【Go】--map和struct数据类型
  • go win安装grpc-gen-go插件