tags:

views:

150

answers:

2
    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 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...

+4  A: 

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

Managu
oh.. I haven't seen that.... thank you..
suresh
+1  A: 

Aside from Managu's answer, don't forget to make sure that your static member function uses C linkage (extern "C") - depending on the implementation, you may not be able to pass a pointer to a function with the default C++ linkage where a pointer to C function is expected (when ABIs differ).

Pavel Minaev