什么是(距离)单词中的问题,其中声明结构? [英] what is problem in (distance) word where declara struct with it ?
问题描述
#include<iostream>
using namespace std;
struct distance
{ int x; };
int main()
{
distance d1; // what is wrong in this word (distance), compiler say {IntelliSense: "distance" is ambiguous}
// i thank this is not recerved key word in c++
return 0;
}
推荐答案
//我感谢这不是c ++中的关键词
// i thank this is not recerved key word in c++
你的假设是正确的。因此,您与 STL
发生冲突( VS 2012
我发现距离
在STL的''i xutility内部标题''内定义。您可以通过使用命名空间std; 或 struct
定义注释来轻松验证这一点(在这两种情况下,模糊性消失)。
Your assumption is right. Hence you have a collision with the STL
(with VS 2012
I found distance
definition inside the STL''s ''xutility internal header''). You may easily verify this either by commenting the using namespace std;
or your struct
definition (in both cases the ambiguity vanishes).
它怎么可能是一个关键字。
以下是你可以解决它的方法:1)重命名struct distance
; 2)在Visual Studio中关注旧名称distance
,使用上下文菜单中的转到定义项。你会看到这个声明。我做到了:
How could it be a keyword.
Here is how you could sort it out: 1) renamestruct distance
; 2) put your cared on the old namedistance
in Visual Studio, use "Go to definition item" of context menu. You will see that declaration. I did it:
template<class _InIt> inline
typename iterator_traits<_InIt>::difference_type
__CLRCALL_OR_CDECL distance(_InIt _First, _InIt _Last)
{ // return distance between iterators
typename iterator_traits<_InIt>::difference_type _Off = 0;
_Distance2(_First, _Last, _Off, _Iter_cat(_First));
return (_Off);
}
这是来自文件 xutility
;显然,你有这个包括通过包括 iostream
。
问题解决了。下次,你可以自己动手。
This is from the file xutility
; apparently, you got this include via included iostream
.
Problem solved. Next time, you will be able to do it by yourself.
这篇关于什么是(距离)单词中的问题,其中声明结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!