I can't get the following code from Accelerated C++ to work. It seems to be a problem with the string interators being passed to the find_if() <algorithm>. The error says the iterator arguments are ambiguous: they could be char* or const char*:
C:\Beginning C++\test2\main.cpp(37) : error C2782: '_II __cdecl std::find_if(_II,_II,_Pr)' : template parameter '_II' is ambiguousCode:#include <iostream> #include <string> #include<vector> #include <algorithm> using namespace std; bool space(char ch) { //if ch is a space, returns true: return isspace(ch)?true:false; } bool not_space(char ch) { //if ch is not a space, returns true: return isspace(ch)?false:true; } int main() { string str = "Although functors and predicates are cool, you" "should be very careful when writing unary and binary functors." "Except when used with the std::for_each algorithm, the context" "they hold should be constant."; vector<string> words; string::const_iterator i = str.begin(); string::const_iterator j = 0; while(i != str.end()) { i = find_if(i, str.end(), not_space); //error //rest of code } return 0; }
could be 'char *'
or 'const char *'



LinkBack URL
About LinkBacks



) of isspace() to a function pointer. Hmmmm...but isn't the name of a function already a pointer to its type, which is already int (*) (int)? I tried it without the casts, and it compiles for me.