Reputation: 7118
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?
Upvotes: 1
Views: 128
Reputation: 73366
With the info you gave, I made a minimal example (with the min modifications, did you include the headers?):
#include <string>
#include <algorithm>
#include <vector>
typedef std::vector<std::string> StringVec;
StringVec colnames;
int colIndex(const std::string &cn) {
StringVec::iterator i1;
i1 = std::find(colnames.begin(),colnames.end(),cn);
return(i1 == colnames.end() ? -1 : (i1 - colnames.begin()));
}
int main() {
return 0;
}
and it compiled just fine with g++ 4.8.4:
gsamaras@gsamaras-A15:~$ g++ -Wall px.cpp
gsamaras@gsamaras-A15:~$
Upvotes: 3