我使用Microsoft Visual影城和我创建一个通用类List_Array。没有与默认的构造函数没有问题,但其他两个(重载)构造函数生成的错误。
//List_Array.h
template<typename T>
class List_Array {
private:
int size; ...
T* data;
public:
List_Array<T>::List_Array();
List_Array<T>::List_Array(int);
List_Array<T>::List_Array(const T&, int);
...
};
template<typename T>
List_Array<T>::List_Array() { }
template<typename T>
List_Array<T>::List_Array(int s) {
this->size = s
this->data = new T[s];
}
template<typename T>
List_Array<T>::List_Array(const T& init, int s){
this->size = s;
this->data = new T[s];
for (int i = 0; i < s; i++){
this->data[i] = init;
}
}
我得到一个C2244“List_Array :: List_Array”:无法定义的功能匹配到现有的声明
任何帮助深表感谢!
这个问题有没有关系模板或超载。你只是不需要的类定义的成员函数声明List_Array<T>::
一部分。即
template<typename T>
class List_Array {
private:
int size; ...
T* data;
public:
List_Array();
List_Array(int);
List_Array(const T&, int);
...
};