C++ 模板(Template)

#include                        

using namespace std;

template
class arr
{
    public:
        //给i位置存放
        int set(int i, T val)
        {
            if(i > 25)
            {
                return -1;
            }
            crr[i] = val;
            return 0;
        }

        //取出i位置数值
        int get(int i, T *res)
        {
            *res = crr[i];
            return 0;
        }

        T &operator[] (int i)
        {
            return crr[i];
        }
    private:
        T crr[25];
};

int main(int argc, const char *argv[])
{
    arr arrint;

    arrint.set(0,70);
    int res;
    arrint.get(0,&res);
    cout<<"res="< arrdouble;
    arrdouble.set(0,77.7);
    double reb;
    arrdouble.get(0,&reb);
    cout<<"res="<

你可能感兴趣的:(c++,算法,开发语言)