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");

}

相关推荐
程与留5 小时前
15_国际化和本地化:tr()、ts 文件、QM 文件、多语言切换
c++·qt
地平线开发者6 小时前
【模型轻量化专题】衡量模型轻量性的指标
算法
程与留7 小时前
14_Qt 样式表(QSS)入门(语法、选择器、美化实战)
c++·qt
学习星球9 小时前
OFDM技术精讲:正交性推导、循环前缀原理与80行Python链路仿真(附实测数据)
算法·面试·前端框架
欧特克_Glodon15 小时前
OpenCV计算机视觉开发入门与实践<二十七>:图像分割概述
c++·人工智能·opencv·计算机视觉
蒸蒸yyyyzwd15 小时前
cpp 选手秋招学习笔记 day21
c++·面试·八股
alphaTao15 小时前
LeetCode 每日一题 2026/8/24-2026/8/30
python·算法·leetcode
Interview Aid11215 小时前
TikTok OA 四题分享|半小时内 AC,题目基本都是实现题
java·开发语言·算法·面试·职场和发展
CoderIsArt1 天前
C#中UI 线程与 Dispatcher
开发语言·ui·c#
顶点多余1 天前
那些在算法中适合巩固的知识点---1
java·前端·算法