2009-10-01 10 views
0
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() 함수이 경우 콜백 함수를 호출하여 얻을 C++의 멤버 함수 "스캐너".. 어떻게이 멤버 함수를 AddToIndex 콜백 함수로 만들 수 있습니까? 이 문제를 해결하는 방법 ...

+0

ftw의 프로토 타입을 볼 수 있습니까? – LiraNuna

+0

@LiraLuna : http://linux.die.net/man/3/ftw 잘 알려진 표준 라이브러리 기능입니다. – ephemient

답변

4

ftw으로 전화하는 경우 첫 번째 매개 변수는 mRootFilePath.c_str입니다. 아마도 mRootFilePath.c_str()을 대신 사용 하시겠습니까?

+0

오 .. 나는 못 봤어 .... 고마워 .. – suresh

1

Manuchu의 대답 외에도 static 멤버 함수가 C 링키지 (extern "C")를 사용하는지 확인하는 것을 잊지 마십시오. 구현에 따라 기본 C++ 링키지가있는 함수에 대한 포인터를 전달하지 못할 수도 있습니다 여기서 C 함수에 대한 포인터가 예상됩니다 (ABI가 다를 때).

관련 문제