#include <iostream>
#include <string.h>
using namespace std;
template <class C> class String
{
C *cont;
public:
String();
String(const C *src);
void output();
};
template <class C>String<C>::String()
{
cont = NULL;
cout << "init a null String" << endl;
}
template <class C>String<C>::String(const C *src)
{
cont = new C[strlen(src)];
strcpy(cont, src);
}
template <class C>void String<C>::output()
{
cout << cont << endl;
return;
}
int
main()
{
String<char> a("abc");
a.output();
return 0;
}
Template Class
最新推荐文章于 2022-11-15 22:43:36 发布