STL 错误_没有_代码中的任何 STL
STL error _without_ any STL in code
我在cygwin上使用gcc 3.4.4。 我在下面的代码中收到这个相当令人困惑的 STL 错误消息,它根本不使用 STL:
#include <iostream>
using namespace std;
const int N = 100;
bool s[N + 1];
bool p[N + 1];
bool t[N + 1];
void find(const bool a[], bool b[], bool c[]){
return;
}
int main(){
find(s, p, t);
return 0;
}
当我编译时 G++ stack.cc
我收到以下错误消息:
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_algo.h: In function `_RandomAccessIterator std::find(_RandomAccessIterator, _RandomAccessIterator, const _Tp&, std::random_access_iterator_tag) [with _RandomAccessIterator = bool*, _Tp = bool[101]]':
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_algo.h:314: instantiated from `_InputIterator std::find(_InputIterator, _InputIterator, const _Tp&) [with _InputIterator = bool*, _Tp = bool[101]]'
stack.cc:18: instantiated from here
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_algo.h:207: error: ISO C++ forbids comparison between pointer and integer
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_algo.h:211: error: ISO C++ forbids comparison between pointer and integer
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_algo.h:215: error: ISO C++ forbids comparison between pointer and integer
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_algo.h:219: error: ISO C++ forbids comparison between pointer and integer
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_algo.h:227: error: ISO C++ forbids comparison between pointer and integer
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_algo.h:231: error: ISO C++ forbids comparison between pointer and integer
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_algo.h:235: error: ISO C++ forbids comparison between pointer and integer
如您所见,代码根本不使用任何 STL,所以这很奇怪。此外,如果我删除该行,错误就会消失
using namespace std;
这暗示了一些命名空间冲突。 如果我从函数的定义中删除 const
关键字,它也消失find
.
另一方面,如果我按如下方式find
2 参数函数,错误也消失了(这相当令人惊讶):
#include <iostream>
using namespace std;
const int N = 100;
bool s[N + 1];
bool p[N + 1];
bool t[N + 1];
void find(const bool a[], bool b[]){
return;
}
int main(){
find(s, p);
return 0;
}
我无法想象 find 可以是两个参数函数而不是三个参数函数的原因是什么。
因此,以下是消除错误的三种方法的简要摘要:
删除
using namespace std;
行。从
find
的定义中删除const
关键字。删除函数的第三个参数
find
。
我想不出任何合乎逻辑的原因,为什么首先应该发生这样的错误,以及为什么应该删除它,我使用上述任何看似完全不相关的步骤。 这是一个记录在案的 g++ 错误吗?我尝试搜索它,但老实说,我不知道要搜索什么,我尝试的几个关键字("没有使用 STL 的 STL 错误")没有出现任何东西。
您只是发生了冲突,因为当您执行 using namespace std;
时,您无意中将std::find
(需要 3 个参数)拉入全局命名空间。 无论出于何种原因,您的<iostream>
#include
<algorithm>
,或其内部实现的一部分(特别是bits/stl_algo.h
)。
我无法解释为什么删除const
会让它消失;也许它会影响编译器解析重载的顺序。
您将编译器与标准库 (std::find) 中的 find 版本混淆了,该版本具有 3 个参数,但不是您拥有的参数。
如果您的代码位于其自己的命名空间中,则可以避免此问题。 或者重命名查找方法或已记录的解决方案。
- 接受任何 STL 容器的函数
- 在不使用任何 STL 容器的情况下删除重复项
- 是否有任何常规方法可以通知 STL 移动和复制构造函数?
- 如何通过键和值以及在C 中的结果映射中比较两个地图?我们有任何STL API吗?
- stl 中是否有任何数据结构可以在 O(1) 或 O(log n) 中插入元素,我可以在其上编写自己的bin_searc
- 方法插入到任何stl集合中
- STL 中是否有任何错误代码异常
- C++ 中 STL 堆栈中的任何垃圾值
- 任何表示具有有序元素的对的 stl/boost 类型
- 是否有任何不属于C++标准库的 STL 标头
- 如何在没有STL的情况下从2d阵列中删除任何未填充的插槽
- STL 错误_没有_代码中的任何 STL
- C++:在 faux-STL 类中使用任何迭代器类型
- C++ -<Task> 删除堆上分配的任务数组时,将列表 l(或任何 STL 容器)添加为数据成员会导致错误
- 从STL列表的任何位置访问头
- 我可以指望sizeof(字符串)或sizeof任何STL容器吗
- 打印任何STL容器
- 是否有任何 STL 算法适用于 2 倍循环
- stl中是否有任何函数可以进行字符串转换,但带有长度参数
- 具有奇数大小的c++ STL向量,在添加任何内容之前容量为0