#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[n] = '\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[n] = '\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");
}