随笔分类 -  <四>:C++模板编程

摘要:.在上一节我们实现的 MyVector存在哪些问题? 问题1 现在有Student类 class Student{ public: Student(){cout<<"构造Student对象"<<endl;} ~Student(){cout<<"析构Student对象"<<endl;} private 阅读全文
posted @ 2022-11-20 19:09 Hello_Bugs 阅读(254) 评论(0) 推荐(0) 编辑
摘要:使用类模板简单实现STL Vector #include <iostream> using namespace std; template<typename T> class MyVector { public: //构造函数 MyVector<T>(int size = 10) { T * _te 阅读全文
posted @ 2022-11-19 17:40 Hello_Bugs 阅读(77) 评论(0) 推荐(0) 编辑
摘要:类模板=>实例化=>模板类 通过类模板实现栈,点击查看代码 #include <iostream> #include <cstring> using namespace std; template<typename T> //template<typename T=int> 也可以这样写,写个默认类 阅读全文
posted @ 2022-11-16 16:13 Hello_Bugs 阅读(75) 评论(0) 推荐(0) 编辑
摘要:函数模板 模板的意义:对类型也参数化 int sum1(int a,int b){return a+b;} double sum2(double a ,double b){return a+b;} 几个概念 函数模板 模板的实例化 模板函数 模板类型参数 模板非类型参数 模板实参推演 模板的特例化 阅读全文
posted @ 2022-11-15 23:31 Hello_Bugs 阅读(120) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示