C++ 01 函数模板

#include <iostream>

#include <string>

#include <fstream>

using namespace std;

template <class T>

void mySwap(T& a, T& b)

{

T temp = a;

a = b;

b = temp;

}

int main()

{

int a = 10;

int b = 20;

mySwap(a, b);

string c = "hello";

string d = "world";

mySwap(c, d);

cout << a << " " << b << endl;

cout << c << " " << d << endl;

system("pause");

}

相关推荐
老鼠只爱大米1 小时前
LeetCode经典算法面试题 #215:数组中的第K个最大元素(快速选择、堆排序、计数排序等多种实现方案详解)
算法·leetcode·堆排序·快速选择·topk·数组中的第k个最大元素
2301_816651221 小时前
C++中的享元模式变体
开发语言·c++·算法
逆境不可逃1 小时前
LeetCode 热题 100 之 35. 搜索插入位置 74. 搜索二维矩阵 34. 在排序数组中查找元素的第一个和最后一个位置
数据结构·算法·leetcode
m0_583203131 小时前
C++中的访问者模式变体
开发语言·c++·算法
浅念-1 小时前
C ++ 智能指针
c语言·开发语言·数据结构·c++·经验分享·笔记·算法
布谷歌1 小时前
Fastjson枚举反序列化:当字符串不是枚举常量名时,会发生什么?
开发语言·python
虚幻如影1 小时前
python识别验证码
开发语言·python
不染尘.1 小时前
最小生成树算法
开发语言·数据结构·c++·算法·图论
ChineHe1 小时前
基础篇003_Python基础语法
开发语言·人工智能·python
Klong.k1 小时前
判断是不是素数题目
数据结构·算法