32
作者:互联网
1 #include <iostream> 2 #include <string> 3 #include <cstring> 4 using namespace std; 5 template <class T> 6 class myclass { 7 private: 8 T* p; 9 int size; 10 public: 11 myclass(T* _p,int _size = 0):size(_size){ 12 p = new T[_size + 1]; 13 for(int i = 0;i < size;++ i) 14 p[i] = _p[i]; 15 } 16 ~myclass( ) { 17 delete [] p; 18 } 19 void Show() 20 { 21 for( int i = 0;i < size;i ++ ) { 22 cout << p[i] << ","; 23 } 24 cout << endl; 25 } 26 }; 27 int a[100]; 28 int main() { 29 char line[100]; 30 while( cin >> line ) { 31 myclass<char> obj(line,strlen(line));; 32 obj.Show(); 33 int n; 34 cin >> n; 35 for(int i = 0;i < n; ++i) 36 cin >> a[i]; 37 myclass<int> obj2(a,n); 38 obj2.Show(); 39 } 40 return 0; 41 }
标签:int,32,++,myclass,line,include,size 来源: https://www.cnblogs.com/balabalabubalabala/p/16691298.html