10.3 设计一个类模板 store <T>用于存储某一类型的数据,并以整数和字符串进行实 例化
2016-08-01 19:59
316 查看
#define _CRT_SECURE_NO_WARNINGS
/*
10.3 设计一个类模板 store <T>用于存储某一类型的数据,并以整数和字符串进行实
例化
*/
#include<iostream>
#include <math.h>
using namespace std;
#define MAX 20
template <typename T>
class store
{
T a[MAX];
int n;
public:
store(T m[],int n)
{
for (int i = 0; i< n; i++)
{
a[i] = m[i];
}
a
= '\0';
}
void disp()
{
for (int i = 0; a[i] != '\0'; i++)
{
cout << " " << a[i];
}
cout <<"\n\n\n"<< endl;
}
};
void main()
{
int a[4] = { 1, 6, 3, 7 };
char b[4] = { 'c', 's', 'w', 'r' };
store<int> s1(a,4);
s1.disp();
store<char> s2(b,4);
s2.disp();
system("pause");
}
/*
10.3 设计一个类模板 store <T>用于存储某一类型的数据,并以整数和字符串进行实
例化
*/
#include<iostream>
#include <math.h>
using namespace std;
#define MAX 20
template <typename T>
class store
{
T a[MAX];
int n;
public:
store(T m[],int n)
{
for (int i = 0; i< n; i++)
{
a[i] = m[i];
}
a
= '\0';
}
void disp()
{
for (int i = 0; a[i] != '\0'; i++)
{
cout << " " << a[i];
}
cout <<"\n\n\n"<< endl;
}
};
void main()
{
int a[4] = { 1, 6, 3, 7 };
char b[4] = { 'c', 's', 'w', 'r' };
store<int> s1(a,4);
s1.disp();
store<char> s2(b,4);
s2.disp();
system("pause");
}
相关文章推荐
- EasyUI 属性网格
- 采用JLink+ADS1.2调试uboot的方法
- Microsoft.XMLHTTP基本用法
- BZOJ 2190
- SDUT2506完美网络
- Html5元素及基本语法
- nyoj 56 因式分解
- POJ 3253 Fence Repair
- 10.2 设计一个函数模板 max <T>求一个数组中最大的元素,并以整数数组和字符数 组进行调用
- 扩展欧几里得算法
- nginx的动态数组--ngx_array_t
- 莫比乌斯反演1003 SPOJ VLATTICE
- NOIP2016 暑期培训 D1
- linphone-LinphoneCallParams.java文件分析
- C++ string
- C++之next_permutation
- 在字符串copy函数中引入辅助指针变量
- SICP_Python版:抽象数据的多重表示
- 【LeetCode】 028. Implement strStr()
- Problem G. Generators ACM ICPC 2015–2016, Northeastern European Regional Contest. St. Petersburg – Barnaul – Tbilisi – Tashkent, December 6, 2015