我已经搜索过 SO 和 google,我没有在两个地方声明相同的变量,也没有以一种奇怪的方式包含一些东西……我知道。插入方法应该可以正常工作,它是一种预先编写的方法(我想这也可能是错误的......哈哈)。这是我得到的错误。
错误:
error C2872: 'range_error' : ambiguous symbol
........ while compiling class template member function 'Error_code List<List_entry>::insert(int,const List_entry &)'
对我来说,插入方法看起来不错,我没有看到与 0 比较的位置变量或在构造函数中声明为 0 以返回 range_error 的计数有任何问题。
插入方法:
template <class List_entry>
Error_code List<List_entry>::insert(int position, const List_entry &x){
Node<List_entry> *new_node, *following, *preceding;
if(position < 0 || position > count){
return range_error;
}
if(position == 0){
if(count == 0) following = nullptr;
else {
set_position(0);
following = current;
}
preceding = nullptr;
}
else {
set_position(position - 1);
preceding = current;
following = preceding->next;
}
new_node = new Node<List_entry>(x, preceding, following);
if(new_node == nullptr) return overflow;
if(preceding != nullptr) preceding->next = new_node;
if(following != nullptr) following->back = new_node;
current = new_node;
current_position = position;
count++;
return success;
}
问题可能在于我没有重载 = 运算符的实现吗?
所有代码都在这里:pastie.org/1258159