Here is a complete example with a "normal" function in addition to a static member function:
void external_function(const float* (*f)(int)){ cout << *(f(3)) << endl; }
// declaration of a "normal" function with the same signature as gc;
// (declaring it here is needed because we refer to it in named::newMethod(),
const float *globally_visible_func(int i2);
class named
{
public: // need to make H accessible for externalgc
static float H[];
private:
static const float *gc( int i)
{
cout << "static function named::gc, arg was " << i << endl;
return( &H[i] );
}
public:
int newMethod()
{
H[3] = 123;
// Use a pointer to the static member function gc as argument
external_function(gc);
// now use a pointer to a "normal" function as argument. There
// is no difference.
external_function(globally_visible_func);
}
};
// A pointer to this "normal" function is used as argument above
const float *globally_visible_func(int i2)
{
cout << "globally_visible_func, arg was " << i2 << endl;
return named::H + i2;
}
float named::H[100]; // must define (i.e. create and initialize) static data member
int main()
{
named n;
n.newMethod();
}