c++ - STL error _without_ any STL in code -
i using gcc 3.4.4 on cygwin. getting rather perplexing stl error message in code below not use stl @ all:
#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; } when compile g++ stack.cc
i following error message:
/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 `_inputiterator std::find(_inputiterator, _inputiterator, const _tp&) [with _inputiterator = bool*, _tp = bool[101]]' stack.cc:18: instantiated here /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_algo.h:207: error: iso c++ forbids comparison between pointer , integer /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_algo.h:211: error: iso c++ forbids comparison between pointer , integer /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_algo.h:215: error: iso c++ forbids comparison between pointer , integer /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_algo.h:219: error: iso c++ forbids comparison between pointer , integer /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_algo.h:227: error: iso c++ forbids comparison between pointer , integer /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_algo.h:231: error: iso c++ forbids comparison between pointer , integer /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/bits/stl_algo.h:235: error: iso c++ forbids comparison between pointer , integer as can see, code not use stl @ all, rather strange. also, error disappears if remove line
using namespace std; which hints @ namespace clash. disappears if remove const keyword definition o function find.
on other had error also disappears (and rather surprising) if make find 2-argument function follows:
#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; } i can't imagine reason why find can 2 argument function not 3 argument one.
so here brief summary of 3 ways remove error:
remove
using namespace std;line.remove
constkeyword definition offind.remove third argument of function
find.
i cannot think of logical reason why such error should happen in first place, , why should removed i use of above seemingly unrelated steps. documented g++ bug? tried searching it, @ loss search for, , few keywords tried ("stl error without stl use") didn't turn anything.
you have collision, because you've unintentionally pulled std::find (which takes 3 arguments) global namespace when did using namespace std;. whatever reason, <iostream> #include-ing <algorithm>, or 1 of parts of internal implementation (specifically, bits/stl_algo.h).
i can't explain why removing const makes go away; perhaps affects order in compiler resolves overloads.
Comments
Post a Comment