0

I am writing a template Array class. I can use it to declare things like this,

Array<int> oneDimenional(5);

But not this...

Array<Array<Array<Array<Array<Array<Array< int >>>>>>> Craziness(1000);

My class starts out like this,

template <typename T>

class Array{

private:
    int len;
    T *arr;
public:
    Array() {
        int len = 0;
    }
    Array(int size) {
        arr = new T[size];
        len = size;
    }
    ~Array() {
        delete[] arr;
    }
//...
};

I'm guessing I need to change my constructor?

4

1 回答 1

2
Array<Array<int> > arr(10);

在 >> 之间留出空格。因为这被认为是>>右移。这就是为什么错误它会在编译器本身中显示,这是一个常见错误。

 error: '>>' should be '> >' within a nested template argument list

所以你的代码应该是

Array<Array<Array<Array<Array<Array<Array< int > > > > > > > Craziness(1000);
于 2013-06-01T06:09:02.773 回答