参数缺省值只能出现在函数的声明中,而不能出现在定义体中
函数 参数 出现 定义 不能 声明 只能
2023-09-14 09:12:03 时间
参数缺省值只能出现在函数的声明中,而不能出现在定义体中 。
1 #include <iostream> 2 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */ 4 using namespace std; 5 //声明函数模板的原型语句 6 template <class T> void swap(T *x, T *y); 7 8 //定义一个结构类型 9 struct student { 10 int n; 11 char name[20]; 12 float grade; 13 }; 14 15 int main(int argc, char** argv) { 16 //交换两个int型变量中的数据 17 int m=3,n=5; 18 cout<<"m="<<m<<" n="<<n<<endl; 19 swap(&m,&n); 20 cout<<"m="<<m<<" n="<<n<<endl; 21 cout<<"-------------------"<<endl; 22 23 //交换两个double型变量中的数据 24 double x=3.5,y=5.7; 25 cout<<"x="<<x<<" y="<<y<<endl; 26 swap(&x,&y); 27 cout<<"x="<<x<<" y="<<y<<endl; 28 cout<<"-------------------"<<endl; 29 30 //交换两个char型变量中的数据 31 char c1='A',c2='a'; 32 cout<<"c1="<<c1<<" c2="<<c2<<endl; 33 swap(&c1,&c2); 34 cout<<"c1="<<c1<<" c2="<<c2<<endl; 35 cout<<"-------------------"<<endl; 36 37 //交换两个结构变量中的数据 38 student s1={1001,"ZhangHua",90}; 39 student s2={1011,"LiWei",95.5}; 40 cout<<"s1: "; 41 cout<<s1.n<<" "<<s1.name<<" "<<s1.grade<<endl; 42 cout<<"s2: "; 43 cout<<s2.n<<" "<<s2.name<<" "<<s2.grade<<endl; 44 45 swap(&s1,&s2); 46 cout<<"swap(s1,s2):"<<endl; 47 cout<<"s1: "; 48 cout<<s1.n<<" "<<s1.name<<" "<<s1.grade<<endl; 49 cout<<"s2: "; 50 cout<<s2.n<<" "<<s2.name<<" "<<s2.grade<<endl; 51 return 0; 52 } 53 54 55 56 //定义名为swap的函数模板用于交换两个变量中的数据 57 template <class T> void swap(T *x, T *y) 58 { 59 T temp; 60 temp=*x; 61 *x=*y; 62 *y=temp; 63 }
相关文章
- 【vc】高精度时间函数的使用
- 文件操作函数fread/fwrite/fseek演示例程
- php glob()函数实现目录文件遍历与寻找与模式匹配的文件路径
- loadrunner12.55:常用函数汇总说明之String Manipulation Functions参数函数
- Python 微分法计算定积分,以及用lambda函数作函数的形参
- OpenCV每日函数 图像过滤模块 (21) Sobel边缘检测函数
- 在SAP Spartacus的convertor函数里,直接修改输入参数target的值,会有什么问题
- NgRx createSelector 工具函数的三个类型参数
- Go语言的可变(不定长)参数函数
- 如何在 SAP BTP ABAP 编程环境里直接调用 ABAP On-Premises 系统的 RFC 函数
- ZZNUOJ_C语言1100:求组合数(函数专题)(完整代码)
- ML之ME/LF:机器学习中的模型评估指标/损失函数(连续型/离散型)的简介、损失函数/代价函数/目标函数之间区别、案例应用之详细攻略
- C++构造函数和析构函数
- cdf(Cumulative Distribution Function)累积分布函数==>小于等于当前数据值的所有数据的概率分布
- 【数字信号处理】基本序列 ( 基本序列列举 | 单位脉冲序列 | 单位脉冲函数 | 离散单位脉冲函数 | 单位脉冲函数 与 离散单位脉冲函数的区别 )
- 回调函数
- Scala学习教程笔记一之基础语法,条件控制,循环控制,函数,数组,集合
- C语言同时在一行声明多个函数,并将指针作为函数的参数
- 关于WinMain函数的第二个参数解释
- 如果虚函数在基类与子类名字相同,而参数类型不同不会进行迟后联编
- 函数符
- C语言进阶之回调函数详解分析方法
- 〖Python全栈白宝书-免费版㉛〗- 函数的定义与使用
- Lecture6:激活函数、权值初始化、数据预处理、批量归一化、超参数选择