issue with quot;using namespace std;quot;(“使用命名空间 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;"的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:“使用命名空间 std;"的问题
基础教程推荐
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- CString 到 char* 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
