函数:使用函数模板,泛型引用,重载进行数据交换
来源:互联网 发布:手机拍照识字软件 编辑:程序博客网 时间:2024/06/07 21:12
#include <iostream>template <typename T>void Swap(T *a, T *b, int n);template <typename T>void Swap(T &a, T &b);void Show(int a[]);const int Lim = 8;int main(void){using std::cout;int i=10, j=20;cout << "i,j = " << i << ", " << j << ".\n";cout << "Using compiler-generated int swapper:\n";Swap(i,j);cout << "Now i, j = " << i << ", " << j << ".\n";int d1[Lim]={0,7,0,4,1,7,7,6};int d2[Lim]={0,7,2,0,1,9,6,9};cout << "Original arrays:\n";Show(d1);Show(d2);Swap(d1,d2,Lim);cout << "Swapped arrays:\n";Show(d1);Show(d2);return 0;}template <typename T>void Swap(T *a, T *b, int n){T temp;for(int i=0; i<n; i++){temp=a[i];a[i]=b[i];b[i]=temp;}}template <typename T>void Swap(T &a, T &b){T temp;temp = a;a = b;b = temp;}void Show(int a[]){using std::cout;using std::endl;cout << a[0] << a[1] << "/";cout << a[2] << a[3] << "/";for(int i=4; i<Lim; i++)cout << a[i];cout << endl;}
阅读全文
0 0
- 函数:使用函数模板,泛型引用,重载进行数据交换
- 函数模板,函数模板重载,可变参数模板,函数模板覆盖,通过引用交换数据
- memcpy函数 & 使用泛型指针交换任何类型数据
- 函数模板 /函数重载
- 函数重载 函数模板
- C经典 写函数进行数据交换
- C++ 函数模板(十四)--template 泛型函数模板、通用函数、重载模板
- 数值交换模板函数
- 内联函数,引用变量,按引用传递参数,默认参数,函数重载,函数模板,函数模板具体化,decltype
- 【笔记】C++函数内联、模板、重载,以及引用
- 引用和函数重载
- 函数重载&引用变量
- 使用const关键字进行函数重载
- 使用const关键字进行函数重载
- 使用const关键字进行函数重载
- c++ :函数模板,指针型函数,引用
- 模板函数重载
- 函数模板重载
- Appendix A. Spring boot 配置属性大全,史上最全application.properties--张振华.Jack
- ImageLoader
- 讲给Android程序员看的前端教程(27)——运算符
- 数据库分片
- MySQL installer安装MySQL 卡在starting serve解决方案
- 函数:使用函数模板,泛型引用,重载进行数据交换
- 【更新】剖析 iOS 11 网页适配问题
- C++ 中include头文件尖括号<>与双引号""的区别
- day 16 lvm讲解
- get post请求的几种方法
- 讲给Android程序员看的前端教程(28)——流程控制
- 通过反射修改ViewPager最小滑动距离mTouchSlop
- UI控件-> ListView(2)
- VMware之EXSI安装-yellowcong