Pointer to Static Member Function.

For the life of me, I cannot figure out how the method prototype differens in the slightest from what the compiler expects:

1
2
3
4
5
6
7
8
9
10
11
12
class Packages {
public:
    static void Load( const char* dir );

private:
    static void LoadPkgRootFile( const char* dir, String& file );
    static void ScanDir( const char* dir, void (Packages::*func)( const char*, String& ) );
};

void Packages::Load( const char* dir ) {
    ScanDir( dir, &Packages::LoadPkgRootFile); // error: no matching function for call to ‘Packages::ScanDir(const char*&, void (*)(const char*, String&))’|
}
Last edited on
Have you tried just getting rid of the "&" in

ScanDir( dir, &Packages::LoadPkgRootFile);

?
It does not seem to make a difference.
If none of the functions are static, it works fine. it's because they are static, but there's got to be some way for this to work...
Pointers to static member functions take the same form as a standard C++
function pointer.
The compiler gave the game away in the way it wrote it error message.

1
2
3
4
5
6
7
8
9
10
11
12
class Packages {
public:
    static void Load( const char* dir );

private:
    static void LoadPkgRootFile( const char* dir, String& file );
    static void ScanDir( const char* dir, void (*func)( const char*, String& ) ); //NOTE: Normal function pointer syntax when dealing with pointer to static member functions.
};

void Packages::Load( const char* dir ) {
    ScanDir( dir, &Packages::LoadPkgRootFile); //Now OK.
}
thank you kindly.
Topic archived. No new replies allowed.