I have class that looks like this:
class A
{
public:
class variables_map vm /*! A boost::program_options variable map containing all program_options in use. */;
char sep_to_space(char c);
template <typename T>
void VectorFromOption(char * sOption, vector<T> & n);
};
char A::sep_to_space(char c){
return c == ',' || c == '<' || c == '>' ? ' ' : c;
}
template <typename T>
void A::VectorFromOption(char * sOption, vector<T> & n)
string s=A::vm[sOption].as<string>();
transform(s.begin(), s.end(), s.begin(), &A::sep_to_space );
stringstream ss(s);
copy(istream_iterator<T>(ss), istream_iterator<T>(), std::back_inserter(n));
}
These work fine outside the class, but I cannot find the correct way to pass sep_to_space() as transform‘s 4th parameter in the context of their being class members. If I comment them out, everything else compiles and runs correctly.
The above &A::sep_to_space produces the enigmatic error:
1>c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\algorithm(671) : error C2064: term does not evaluate to a function taking 1 arguments
which is currently over my head, I’m afraid. Suggestions?
Why is
sep_to_spaceeven a (non-static) member ofA? It doesn’t access any members and obviously doesn’t need to. Make it a free function or a static member and everything is fine.To answer the general question, though, you need to bind the member to the object it’s being called on.
One option is to use the
bindfunction from C++11 or Boost:Or, if you already have C++11 available anyways, just use a lambda: