1
嗨,我仍然不知道爲什麼我收到此錯誤信息:使用類模板需要模板參數
類模板「陣」的使用需要模板參數
標題:
#ifndef Array_h
#define Array_h
template< typename T>
class Array
{
public:
Array(int = 5);
Array(const Array &);
const Array &operator=(Array &);
T &operator[](int);
T operator[](int) const;
// getters and setters
int getSize() const;
void setSize(int);
~Array();
private:
int size;
T *ptr;
bool checkRange(int);
};
#endif
CPP文件
template< typename T >
const Array &Array<T>::operator=(Array &other)
{
if(&other != this)
{
if(other.getSize != this->size)
{
delete [] ptr;
size = other.getSize;
ptr = new T[size];
}
for (int i = 0; i < size; i++)
{
ptr[i] = other[i];
}
}
return *this;
}
問題似乎與返回一個const引用對象。
謝謝。編譯器看到Array<T>::