1
我正在使用Microsoft Visual Studios,並且我創建了一個泛型類List_Array。默認構造函數沒有問題,但其他兩個(重載)構造函數生成錯誤。C2244模板構造函數過載錯誤
//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」:無法定義的功能匹配到一個現有的聲明
任何幫助,非常感謝!
謝謝!我沒有意識到這會導致問題。 –
@TylerHughes注意對於非模板類也是如此。所以這個問題與模板和重載無關。 – songyuanyao