我想写一个模板类的拷贝构造函数。我有这个类:模板类拷贝构造函数
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