kin*_*er1 0 c++ linux gcc stl transform
我在使用transform时面临编译错误:
它与我之前的问题有关:C++:如何将字符串对象复制到int数组?)
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();
Run Code Online (Sandbox Code Playgroud)
错误是:
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)'
Run Code Online (Sandbox Code Playgroud)
谁能帮帮我吗?我正在使用gcc(g ++)编译器.
最好的恕我直言,将改变定义
int get_digit(char c)
Run Code Online (Sandbox Code Playgroud)
至
static int get_digit(char c)
Run Code Online (Sandbox Code Playgroud)
它应该与此(静态函数)一起使用.可以使用成员函数进行转换,但稍微复杂一些.而且,你不需要它.
| 归档时间: |
|
| 查看次数: |
1345 次 |
| 最近记录: |