032 这个模板并不难

#include <iostream>
#include <string>
#include <cstring>
using namespace std;
template <class T>
class myclass {

    // 在此处补充你的代码
public:
    T * p;
    int size;
    myclass(){}
    myclass(T * ar,int l): size(l){
        p = new T[size];
        for (int i = 0;i < size;i++) {
            p[i] = ar[i];
        }
    }

    ~myclass() {
        delete[] p;
    }
    void Show()
    {
        for (int i = 0;i < size;i++) {
            cout << p[i] << ",";
        }
        cout << endl;
    }
};
int a[100];
int main() {
    char line[100];
    while (cin >> line) {
        myclass<char> obj(line, strlen(line));;
        obj.Show();
        int n;
        cin >> n;
        for (int i = 0;i < n; ++i)
            cin >> a[i];
        myclass<int> obj2(a, n);
        obj2.Show();
    }
    return 0;
}

posted @ 2022-02-24 13:14  icefield817  阅读(45)  评论(0编辑  收藏  举报