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>::