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

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

问题描述

我有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.0 \ vc \ include \ xutility(364):错误C2039:'iterator_category':不是'myPoint'的成员
1> d:... \ source.cpp(5):参见'myPoint'的声明
...

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

当我删除using namespace std;时 并将cout << distance(A, B) << endl;更改为 std::cout << distance(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

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

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