jeudi 28 avril 2016

GNU g++ 4.9.2 Compilation Error for a find function call

I have StringVec defined as :

typedef std::vector<string> StringVec;

Variable colnames is defined as:

StringVec colnames;

And I have a function as below:

int colIndex(const string &cn) const {
        StringVec::iterator i1;
        i1 = find(colnames.begin(),colnames.end(),cn);
        return(i1 == colnames.end() ? -1 : (i1 - colnames.begin()));
}

When I try to compile with GNU g++ 4.9.2 (C++11), it complains:

error: no matching function for call to 'find(std::vector<std::basic_string<char> >::const_iterator, std::vector<std::basic_string<char> >::const_iterator, const string&)'
 i1 = find(colnames.begin(),colnames.end(),cn);

Even std::find couldn't solve this. Another clue is given by compiler:

note:   template argument deduction/substitution failed:
note:   '__gnu_cxx::__normal_iterator<const std::basic_string<char>*, std::vector<std::basic_string<char> > >' is not derived from 'std::istreambuf_iterator<_CharT>'
  i1 = std::find(colnames.begin(),colnames.end(),cn);

Any clue?

Aucun commentaire:

Enregistrer un commentaire