摘要:
#include<iostream> #include<stdlib.h> #include<string> using namespace std; /* 1.3.2类模板和模板函数的区别 1. 类模板没有自动类型推导的使用方式 2. 类模板在模板参数列表中可以有默认参数(函数模板不可以有默认) 阅读全文
posted @ 2021-04-17 21:18
yub4by
阅读(85)
评论(0)
推荐(0)
摘要:
#include<iostream> #include<stdlib.h> #include<string> using namespace std; /* 1.3类模板 1.3.1类模板语法 作用:建立一个通用类,类中的成员 数据类型可以不具体制定,用一个虚拟的类型来代表 语法:template< 阅读全文
posted @ 2021-04-17 20:09
yub4by
阅读(66)
评论(0)
推荐(0)
摘要:
#include<iostream> #include<stdlib.h> #include<string> using namespace std; /* 1.2.6模板的局限性 模板的通用性并不是万能的 */ // **************************************** 阅读全文
posted @ 2021-04-17 20:08
yub4by
阅读(59)
评论(0)
推荐(0)
摘要:
#include<iostream> #include<stdlib.h> #include<string> using namespace std; /* 1.2.5普通函数和函数模板的调用规则 1. 如果函数模板和普通函数都可以实现,优先调用普通函数 2. 可以通过空模板参数列表来强制调用函数模 阅读全文
posted @ 2021-04-17 20:07
yub4by
阅读(52)
评论(0)
推荐(0)
摘要:
#include<iostream> #include<stdlib.h> #include<string> using namespace std; /* 1.2.4 普通函数和函数模板的区别 普通函数调用时可以发生自动类型转换(隐式类型转换) 函数模板调用时,如果利用自动类型推导,不会发生隐式类 阅读全文
posted @ 2021-04-17 20:06
yub4by
阅读(52)
评论(0)
推荐(0)
摘要:
#include<iostream> #include<stdlib.h> #include<string> using namespace std; /* 1.2.3函数模板案例 利用函数模板封装一个排序的函数,可以对不同数据类型数组进行排序 排序规则从大到小,排序算法为选择排序 */ templ 阅读全文
posted @ 2021-04-17 20:05
yub4by
阅读(52)
评论(0)
推荐(0)
摘要:
#include<iostream> #include<stdlib.h> #include<string> using namespace std; /* 1.2.2函数模板注意事项 自动类型推导,必须推导出一致的数据类型T,才可以使用 模板必须要确定出T的数据类型,才可以使用 */ templa 阅读全文
posted @ 2021-04-17 20:04
yub4by
阅读(60)
评论(0)
推荐(0)
摘要:
#include<iostream> #include<stdlib.h> #include<string> using namespace std; /* 1.1模板概念 C++另一种编程思想称为 泛型编程 ,主要利用的技术就是模板 C++提供两种模板机制:函数模板和类模板 */ /* 1.2函数 阅读全文
posted @ 2021-04-17 20:03
yub4by
阅读(51)
评论(0)
推荐(0)
摘要:
work.h #pragma once#include#includeusing namespace std;// 职工抽象类class Worker{public: int id; string name; int dept_id; ... 阅读全文
posted @ 2021-04-17 15:17
yub4by
阅读(166)
评论(0)
推荐(0)