4

I have the following code:

#include <algorithm>
#include <vector>
#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{   
    typedef vector<int> IntContainer;
    typedef IntContainer::iterator IntIterator;

    IntContainer vw;

    IntIterator i = find(vw.begin(), vw.end(), 5);

    if (i != vw.end()) 
        {
        printf("Find 5 in vector\n");   // found it
      }
        else 
        {
            printf("Couldn't find 5 in vector\n");  // couldn't found it
        }

    return 0;
}

I try to compile it on Ubuntu with gcc 4.7.1 and get the following error:

vec_test.cpp: In function ‘int main()’:
vec_test.cpp:27:46: error: no matching function for call to ‘find(std::vector<int>::iterator, std::vector<int>::iterator, int)’
vec_test.cpp:27:46: note: candidate is:
In file included from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/locale_facets.h:50:0,
                 from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/basic_ios.h:39,
                 from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/ios:45,
                 from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/ostream:40,
                 from /usr/local/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/iostream:40,
                 from vec_test.cpp:3:
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/streambuf_iterator.h:371:5: note: template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT2, std::char_traits<_CharT> > >::__type std::find(std::istreambuf_iterator<_CharT2, std::char_traits<_CharT> >, std::istreambuf_iterator<_CharT2, std::char_traits<_CharT> >, const _CharT2&)
/usr/local/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/streambuf_iterator.h:371:5: note:   template argument deduction/substitution failed:
vec_test.cpp:27:46: note:   ‘__gnu_cxx::__normal_iterator<int*, std::vector<int> >’ is not derived from ‘std::istreambuf_iterator<_CharT2, std::char_traits<_CharT> >’

This code doesn't do anything since the vector is not initialized with any content but it should compile.

I suspect this is a gcc problem but after lots of digging I'm quit desperate. Please let me know if anyone encountered this problem and knows how to solve it.

Ferdinand.kraft
  • 12,579
  • 10
  • 47
  • 69
Orit Dermer
  • 41
  • 1
  • 2
  • [Works in IDEone](http://ideone.com/5znvNJ) and [on my Mac](http://dl.dropbox.com/u/4960980/Screen%20Shot%202013-03-07%20at%2012.53.18%20PM.png) with `clang++` as well. –  Mar 07 '13 at 11:52
  • I suspect that Orit is having a gcc problem you don't have :) – Nitay Mar 07 '13 at 12:07

1 Answers1

0

Maybe some file defines a function find in global namespace?

Have you tried specifying full-scope? That's to say, std::find instead of find. It could help deleting that weird line:

using namespace std;

However, it is not what I would expect. I would call it a bug.

Community
  • 1
  • 1
GdelP
  • 153
  • 9