“使用命名空间 std;"的问题 [英] issue with "using namespace std;"

查看:110
本文介绍了“使用命名空间 std;"的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 C++ 源代码文件.这里是:

I have a source code file in C++. Here it is:

#include <iostream>
using namespace std;

class myPoint
{
public:
    double x;
    double y;
    myPoint() {x=y=0;}
};

double distance(myPoint A, myPoint B)
{
    return (A.x - B.x);
}

int main()
{
    myPoint A, B;
    A.x=5; A.y=5;
    B.x=3; B.y=2;
    cout << distance(A, B) << endl;
    return 0;
}

我的编译器(Microsoft Visual Studio C++ 2012)给了我以下错误:

And my compiler (Microsoft Visual Studio C++ 2012) gives me the following error:

...
1>c:program files (x86)microsoft visual studio 11.0vcincludexutility(364): error C2039: 'iterator_category' : is not a member of 'myPoint'
1> d:...source.cpp(5) : 见 'myPoint' 的声明
...

...
1>c:program files (x86)microsoft visual studio 11.0vcincludexutility(364): error C2039: 'iterator_category' : is not a member of 'myPoint'
1> d:...source.cpp(5) : see declaration of 'myPoint'
...

当我删除 using namespace std;并更改了 cout <<距离(A, B) <<endl;std::cout <<距离(A, B) <<std::endl;我的程序成功了.

When I removed using namespace std; and changed cout << distance(A, B) << endl; to std::cout << distance(A, B) << std::endl; my program worked.

为什么第一个版本给我一个错误?什么错误?

Why does the first version give me an error? What is the mistake?

推荐答案

你和std::distance冲突

这篇关于“使用命名空间 std;"的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆