错误C2872:'range_error':模糊符号

kno*_*lya 1 c++ pointers visual-studio-2010 ambiguous

我已经搜索了SO和google,我没有在两个地方声明相同的变量,也没有以奇怪的方式包含某些内容......我知道.插入方法应该工作正常,这是一个预先编写的方法(我想这也可能是错的..大声笑).这是我得到的错误.

错误:

error C2872: 'range_error' : ambiguous symbol
........ while compiling class template member function 'Error_code List<List_entry>::insert(int,const List_entry &)'
Run Code Online (Sandbox Code Playgroud)

对我来说,insert方法看起来没问题,我没有看到与0比较的位置变量或在构造函数中声明为0的count返回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;
}
Run Code Online (Sandbox Code Playgroud)

可能问题在于我没有overloaded =运算符的实现?

所有代码在这里:pastie.org/1258159

Mik*_*our 7

range_error在您的代码(在全局命名空间中)和标准库(在std命名空间中)中定义.使用using namespace std;将整个Standard命名空间拖动到全局命名空间会产生歧义.您应该至少执行以下操作之一:

  • using namespace std从全局命名空间中删除; 要么使用函数中的命名空间,要么只使用您需要的名称,或者在使用它们时限定所有标准名称
  • 仔细选择自己的名字,以避免与标准名称冲突
  • 将您自己的名称放在命名空间内(并且不要将其拉入全局命名空间).