Curnelious Curnelious - 1 year ago 85
C++ Question

Calling function pointer from static function

Inside some class called

, I have a static function.

I would like to "fire" a delegate from it ,

Inside Light.h

static float intepreterDelegate(char *arg){

// here I need to call the function pointer inside Light itself
Light b;
return b.fpAction(arg); // ** error: "expected unqualified id"

float (*fpAction)(char*) = 0 ; // the actual pointer

How would I create the right syntax for this ?




ERROR: right hand operator to * has non.

Answer Source
float (*fpAction)(char*) = 0 ; // the actual pointer 

this creates a regular function pointer, not a member-function pointer. change to

float (Light::*fpAction)(char*) = 0 ;

calling this function pointer on the Light instance named b

float result = (b.*b.fpAction)("arg");

P.S. if you're wondering what the double b is doing there. it's really (b.*(b.fpAction))("arg"); b.fpAction identifies the pointer as member of Light instance b. (b.*pointer)("arg") calls the functionpointer using 'b' as 'this' value inside the function.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download