上一页 1 ··· 79 80 81 82 83 84 85 86 87 ··· 92 下一页
摘要: #include<iostream> #include<stdlib.h> #include<string> using namespace std; /* 1.3.8类模板与友元 掌握类模板配合友元函数的类内和类外实现 全局函数类内实现 - 直接在类内声明友元即可 全局函数类外实现 - 需要提前让 阅读全文
posted @ 2021-04-18 14:16 yub4by 阅读(60) 评论(0) 推荐(0)
摘要: person.h #pragma once #include<iostream> #include<string> using namespace std; template<class T1, class T2> class Person{ public: T1 name; T2 age; Per 阅读全文
posted @ 2021-04-18 14:15 yub4by 阅读(76) 评论(0) 推荐(0)
摘要: #include<iostream> #include<stdlib.h> #include<string> using namespace std; #include<typeinfo> /* 1.3.6类模板成员函数类外实现 */ template<class T1, class T2> cla 阅读全文
posted @ 2021-04-18 14:12 yub4by 阅读(70) 评论(0) 推荐(0)
摘要: #include<iostream> #include<stdlib.h> #include<string> using namespace std; #include<typeinfo> /* 1.3.5类模板与继承 当子类继承的父类是一个类模板时,子类在声明的时候,要指定出父类中T的类型 如果不 阅读全文
posted @ 2021-04-18 14:11 yub4by 阅读(102) 评论(0) 推荐(0)
摘要: #include<iostream> #include<stdlib.h> #include<string> using namespace std; #include<typeinfo> /* 1.3.4类模板对象做函数参数 类模板实例化出的对象,向函数传参的方式 共有三种传入方式: 1. 指定传 阅读全文
posted @ 2021-04-18 11:19 yub4by 阅读(78) 评论(0) 推荐(0)
摘要: #include<iostream> #include<stdlib.h> #include<string> using namespace std; /* 1.3.3类模板中成员函数创建时机 类模板中成员函数和普通类中成员函数创建时机是有区别的: 普通类中的成员函数一开始就可以创建 类模板中的成员 阅读全文
posted @ 2021-04-17 21:19 yub4by 阅读(74) 评论(0) 推荐(0)
摘要: #include<iostream> #include<stdlib.h> #include<string> using namespace std; /* 1.3.2类模板和模板函数的区别 1. 类模板没有自动类型推导的使用方式 2. 类模板在模板参数列表中可以有默认参数(函数模板不可以有默认) 阅读全文
posted @ 2021-04-17 21:18 yub4by 阅读(97) 评论(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 阅读(78) 评论(0) 推荐(0)
摘要: #include<iostream> #include<stdlib.h> #include<string> using namespace std; /* 1.2.6模板的局限性 模板的通用性并不是万能的 */ // **************************************** 阅读全文
posted @ 2021-04-17 20:08 yub4by 阅读(72) 评论(0) 推荐(0)
摘要: #include<iostream> #include<stdlib.h> #include<string> using namespace std; /* 1.2.5普通函数和函数模板的调用规则 1. 如果函数模板和普通函数都可以实现,优先调用普通函数 2. 可以通过空模板参数列表来强制调用函数模 阅读全文
posted @ 2021-04-17 20:07 yub4by 阅读(64) 评论(0) 推荐(0)
上一页 1 ··· 79 80 81 82 83 84 85 86 87 ··· 92 下一页