I am facing a compilation error on using transform:
It is related to my previous question: C++: How to copy a string object to an int array?)
enter code here
class BinaryCode {
public:
int get_digit(char c)
{
return c-'0';
}
void decode(string decd)
{
int i;
std::vector<int>decoded(decd.size());
std::transform(decd.begin(), decd.end(), decoded.begin(), get_digit);
int length=decoded.length();
The error is:
enter code here
[root@localhost topcoder]# g++ prog1.c
prog1.c: In member function `void BinaryCode::decode(std::string)':
prog1.c:20: error: argument of type `int (BinaryCode::)(char)' does not match `int (BinaryCode::*)(char)'
Can anyone please help me? I am using a gcc (g++) compiler.
The best IMHO would be to change the definition of
to
It should work with this (static function). It is possible to transform using member functions, but it’s slightly more complicated. Moreover, you don’t need it.