对结尾的引用是模棱两可的
Reference to end is ambiguous
谁能解释为什么我得到"对'结束'的引用是模棱两可的"是以下代码?我明白这是因为与 std::end 的冲突。但是如果我把结尾放在主函数内,它不会显示错误。在全局范围内定义与在主函数的作用域中定义有何不同?
#include<bits/stdc++.h>
using namespace std;
int *end;
int main() {
return end == NULL;
}
prog.cpp: In function 'int main()':
prog.cpp:7:12: error: reference to 'end' is ambiguous
return end == NULL;
^
prog.cpp:4:6: note: candidates are: int* end
int *end;
^
In file included from /usr/include/x86_64-linux-gnu/c++/5/bits/stdc++.h:94:0,
from prog.cpp:1:
/usr/include/c++/5/valarray:1226:5: note: template<class _Tp> const _Tp* std::end(const std::valarray<_Tp>&)
end(const valarray<_Tp>& __va)
^
/usr/include/c++/5/valarray:1216:5: note: template<class _Tp> _Tp* std::end(std::valarray<_Tp>&)
end(valarray<_Tp>& __va)
^
In file included from /usr/include/c++/5/string:51:0,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/istream:38,
from /usr/include/c++/5/sstream:38,
from /usr/include/c++/5/complex:45,
from /usr/include/c++/5/ccomplex:38,
from /usr/include/x86_64-linux-gnu/c++/5/bits/stdc++.h:52,
from prog.cpp:1:
/usr/include/c++/5/bits/range_access.h:97:5: note: template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])
end(_Tp (&__arr)[_Nm])
^
/usr/include/c++/5/bits/range_access.h:78:5: note: template<class _Container> decltype (__cont.end()) std::end(const _Container&)
end(const _Container& __cont) -> decltype(__cont.end())
^
/usr/include/c++/5/bits/range_access.h:68:5: note: template<class _Container> decltype (__cont.end()) std::end(_Container&)
end(_Container& __cont) -> decltype(__cont.end())
^
In file included from /usr/include/c++/5/bits/range_access.h:36:0,
from /usr/include/c++/5/string:51,
from /usr/include/c++/5/bits/locale_classes.h:40,
from /usr/include/c++/5/bits/ios_base.h:41,
from /usr/include/c++/5/ios:42,
from /usr/include/c++/5/istream:38,
from /usr/include/c++/5/sstream:38,
from /usr/include/c++/5/complex:45,
from /usr/include/c++/5/ccomplex:38,
from /usr/include/x86_64-linux-gnu/c++/5/bits/stdc++.h:52,
from prog.cpp:1:
/usr/include/c++/5/initializer_list:99:5: note: template<class _Tp> constexpr const _Tp* std::end(std::initializer_list<_Tp>)
end(initializer_list<_Tp> __ils) noexcept
^
编译器在使用using namespace std;
将整个std
命名空间引入当前(全局(作用域后,无法区分(全局(int* end
和 std::end。避免使用using namespace std;
.
相关文章:
- 将对象数组的引用传递给函数
- 什么时候在C++中返回常量引用是个好主意
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 何时在引用或唯一指针上使用移动语义
- 如何在c++中使用引用实现类似python的行为
- 编译C++时未定义的引用
- Ctypes wstring通过引用传递
- c++r值引用应用于函数指针
- 理解c++中的引用
- C++取消引用指针.为什么会发生变化
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- 在SESHAT中,对"元组"的引用是模棱两可的
- 对结尾的引用是模棱两可的
- 如果铸造运算符对类型和引用类型的引用,为什么直接列表初始化会导致类型参考铸件的模棱两可
- C 汇编错误:对构造函数的引用是模棱两可的
- 2 第三方 C 和 C++ 库与 Object 具有相同的类和结构名称,所以我得到这个引用'Object'是模棱两可的错误
- 为什么我的程序对wstring错误给出模棱两可的引用?
- 任何对模棱两可的引用的优雅解决方案