在c ++中回调成员函数 [英] call back member function in c++

查看:164
本文介绍了在c ++中回调成员函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    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();


}

当我编译此代码时,消息

When I compile this code I get error message

 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作为回调函数?如何解决此问题...

ftw function calls the call back function in this case AddToIndex() function which is a member function of the class "scanner".. how can make this member function AddToIndex as a call back function? And How to resolve this issue...

推荐答案

在您致电 ftw ,第一个参数是 mRootFilePath.c_str 。也许你想要 mRootFilePath.c_str()吗?

In your call to ftw, the first parameter is mRootFilePath.c_str. Perhaps you want mRootFilePath.c_str() instead?

这篇关于在c ++中回调成员函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆