- 博客(4)
- 收藏
- 关注
原创 类模板
类模板#include<iostream>using namespace std;template<class T>class Person{ public: Person(T id,T age){ this->mAge=age; this->mId=id; } void Show(){ cout<<"ID:"<<mId<<" Age:"<<mAge<<endl;
2021-02-22 23:42:07
123
原创 使用函数模板对不同类型数组排序
使用函数模板对不同类型数组排序#include<iostream>using namespace std;//使用类模板对char类型和int类型数组进行排序template<class T>void PrintArray(T* arr,int len){ for(int i=0;i<len;i++) { cout<<arr[i]<<" "; } cout<<endl;}//排序template<clas
2021-02-22 23:40:49
436
原创 函数模板
函数模板:类型参数化,编写代码可以忽略类型。#include<iosteam>using namespace std;template<class T> //template<typename T> //告诉编译器 下面写模板函数void MySwap(T& a,T& b){ T temp = a; a = b; b = temp;}void test(){ //自动类型推导 int a=10,b=20; cout<
2021-01-23 22:13:44
116
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人