您的位置:首页 > 其它

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");

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: