第十四周项目61-数组类模板
来源:互联网 发布:iphone x抢购软件 编辑:程序博客网 时间:2024/05/21 12:49
- /*
- *Copyright (c) 2015,烟台大学计算机学院
- *All rights reserved.
- *文件名称:text.cpp
- *作者:李德彪
- *完成日期:2015年6月1日
- *版本号:v1.0
- *
- *问题描述:在数组类的基础上,将之改造为类模板,以使数组中可以存储各种类型的数据
- *输入描述: 无
- *程序输出:数组类中存储的各种类型的数据
- */
- #include <iostream>
- using namespace std;
- template <class T> //数组类模板定义
- class Array
- {
- public:
- Array(T *l,int s)
- {
- size=s;
- list=new T[size];
- for(int i=0;i<size;i++)
- list[i]=l[i];
- }
- Array(const Array<T>&A)
- {
- size=A.size;
- list=new T[size];
- for(int i=0;i<size;i++)
- {
- list[i]=A.list[i];
- }
- }
- ~Array(){delete[] list;}
- void Show()
- {
- for(int i=0;i<size;i++)
- cout<<list[i]<<" ";
- cout<<endl;
- }
- T& operator[](int i)
- {
- return list[i];
- }
- private:
- T* list; //用于存放动态分配的数组内存首地址
- int size; //数组大小(元素个数)
- };
- int main()
- {
- int a[5]={1,2,3,4,5};
- double b[5]={1.1,2.2,3.3,4.4,5.5};
- Array<int> a1(a,5);
- a1.Show();
- Array<double> a2(b,5);
- a2.Show();
- return 0;
- }
0 0
- 第十四周项目61-数组类模板
- 第十四周项目61-数组类模板
- 第十四周项目 3 数组类模板
- 第十四周项目四 数组类模板
- 第十四周项目三 数组类模板
- 第十四周项目4:数组类模板
- 第十四周项目三-数组类模板
- 第十四周项目三 数组类模板
- 第十四周项目三-数组类模板
- 第十四周项目三数组类模板
- 第十四周项目3—数组类模板
- 第十四周项目3—数组类模板
- 第十四周上机实践项目3:数组类模板
- 第十四周——数组类模板
- 第十四周=--数组类模板
- 第十四周上机实践——项目3-数组类模板
- 第十四周实践项目3————数组类模板
- 第十四周项目2.1 两个成员的类模板 (1)
- CentOS 6.4下编译安装MySQL 5.6.14
- 【框架】iOS框架研究
- The Biggest Changes in C++11 (and Why You Should Care)
- iOS tableView背景图和cell背景图
- patch -p0 与patch -p1的区别
- 第十四周项目61-数组类模板
- unity学习笔记(1)-hello unity
- Linux 计划任务布控
- Qt学习之路_6(Qt局域网聊天软件)
- 互联网时代,人人均可开启自助数据分析之旅
- 关于java.lang.IllegalArgumentException: View not attached to window manager 错误的分析
- 设定特定域用户或者组无限次数将计算机加入域
- Leetcode 237. Delete Node in a Linked List
- 华为正在力挺的NB-IoT是什么鬼!