【发布时间】:2009-10-01 20:34:49
【问题描述】:
class scanner
{
private:
string mRootFilePath;
static int AddToIndex( const char *,const struct stat *,int);
public:
scanner(string aRootFilePath){
mRootFilePath = aRootFilePath;
}
string GetFilepath(){
return mRootFilePath;
}
void Start();
};
int scanner :: AddToIndex(const char *fpath, const struct stat *sb,int typeflag)
{
fprintf(stderr,"\n%s\t%d",fpath,typeflag);
return 0;
}
void scanner :: Start()
{
ftw(mRootFilePath.c_str,(int (*)( const char *,const struct stat *,int))scanner :: AddToIndex,200);
}
main()
{
int i;
scanner test(".");
test.Start();
}
当我编译这段代码时,我收到错误消息
main.c: In member function ‘void scanner::Start()’:
main.c:34: error: argument of type ‘const char* (std::basic_string<char, std::char_traits<char>, std::allocator<char> >::)()const’ does not match ‘const char*’
ftw 函数在这种情况下调用回调函数 AddToIndex() 函数,它是“扫描器”类的成员函数..如何使这个成员函数 AddToIndex 作为回调函数?以及如何解决这个问题...
【问题讨论】:
-
@LiraLuna: linux.die.net/man/3/ftw 是众所周知的标准库函数。