我想寫一個模板類的拷貝構造函數。我有這個類:模板類拷貝構造函數
template<int C>
class Word {
array<int, C> bitCells; //init with zeros
int size;
public:
//constructor fill with zeros
Word<C>() {
//bitCells = new array<int,C>;
for (int i = 0; i < C; i++) {
bitCells[i] = 0;
}
size = C;
}
Word<C>(const Word<C>& copyObg) {
size=copyObg.getSize();
bitCells=copyObg.bitCells;
}
}
我有錯誤,與拷貝構造函數,在intilizeing大小的線,我得到: 「在這一行 多個標記 - 過客‘常量字< 16>’作爲「這INT字的論點 '::的getSize()與詮釋C = 16]' 丟棄預選賽[ - fpermissive] - 參數無效 '考生:整數的getSize()'」
什麼是錯與此? 謝謝
第一步:在構造函數名稱後面刪除''。 –
根據該錯誤,您的代碼片段中不包含的成員'getSize()'是非''const'成員:使其成爲'const'成員。 –
是這樣的:「Word(const Word&copyObg)」?這是爲什麼? (仍然是相同的錯誤..) –
Atheel