gpt4 book ai didi

c++ - c++中回调成员函数

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:54:29 25 4
gpt4 key购买 nike

    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() 函数,它是类“scanner”的成员函数。.如何使这个成员函数 AddToIndex 作为回调函数?以及如何解决这个问题......

最佳答案

在调用 ftw 时,第一个参数是 mRootFilePath.c_str。也许您需要 mRootFilePath.c_str() 来代替?

关于c++ - c++中回调成员函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1506313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com