C++ 对“距离”的引用不明确

C++ 对“距离”的引用不明确,c++,visual-c++,C++,Visual C++,在编译以下代码时,我得到的错误如下 对“距离”的引用不明确 谁能帮我纠正这个错误吗。 并为我提供解决方案,以及为什么会出现此错误。这就是原因。您的类距离与标准函数冲突。摆脱使用名称空间std;如果要使用标准组件,每次使用时都要使用std::name\u of theu thing,或者可以使用std::name\u of theu thing。您的类名与名称空间中的另一个符号冲突,将类名更改为距离之类的其他符号将是一种可能的解决方案。这是您的真实代码吗?当前,距离构造函数是私有的。您的距离不明确

在编译以下代码时,我得到的错误如下

对“距离”的引用不明确

谁能帮我纠正这个错误吗。
并为我提供解决方案,以及为什么会出现此错误。

这就是原因。您的类距离与标准函数冲突。摆脱使用名称空间std;如果要使用标准组件,每次使用时都要使用std::name\u of theu thing,或者可以使用std::name\u of theu thing。

您的类名与名称空间中的另一个符号冲突,将类名更改为距离之类的其他符号将是一种可能的解决方案。

这是您的真实代码吗?当前,距离构造函数是私有的。您的距离不明确,因为使用了命名空间std;,还有std::距离函数。永远不要这样做。我认为使用名称空间std;是一个更好的解决方案。好吧,不管这个解决方案的理由是什么,是的,我倾向于同意你的观点,在这里识别问题可能更重要
    #include<iostream>
using namespace std;
class distance
{
    int feet,inches;
    distance():feet(0),inches(0)
    {

    }
    distance(int f,int i):feet(f),inches(i)
    {
    }

    void show()

    {
        cout<<"feet  "<<feet;
        cout<<endl<<"inches   "<<inches;
    }

    distance operator + (distance) ;
};

distance distance::operator + (distance d)
{
    int f,i;
    f=feet+d.feet;
    i=inches+d.inches;
    return distance(f,i);
}

int main()
{
    distance d1;
    distance d2(2,3),d3(7,5);;
d1=d2+d3;
d1.show();
}