C++ 从静态函数调用函数指针

C++ 从静态函数调用函数指针,c++,C++,在一个名为Light的类中,我有一个静态函数 我想从中“解雇”一名代表 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 unqual

在一个名为
Light
的类中,我有一个静态函数

我想从中“解雇”一名代表

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 
我如何为此创建正确的语法

b.(*fpAction)("arg");
编辑:

(b.*b.fpAction)(arg);

错误:右侧运算符到*具有非。

您的类型错误:

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

float (Light::*fpAction)(char*) = 0 ; // the actual pointer
然后

fpAction = &Light::myMethod;

这将创建常规函数指针,而不是成员函数指针。 改为

float (Light::*fpAction)(char*) = 0 ;
在名为
b

float result = (b.*b.fpAction)("arg");
附言。 如果你想知道双b在那里做什么。 它实际上是(b.*(b.fpAction))(“arg”); b、 fpAction将指针标识为灯光实例b的成员。
(b*指针)(“ARG”)调用函数指针,使用函数中的“B”作为“这个”值。

我不知道MVCE错误是什么,不是整个世界都是C++程序员。你有一个具体的答案吗?你需要一个成员函数指针,在
interpretateDelegate
函数中使用它之前,你必须声明它。@Curnelious他问,你提供给我们的是什么。可能重复或相关:非常感谢的可能重复,但是:return(b.*fpAction)(arg);给出错误:“无效使用派系”,即使我更改为您在这里显示的内容。谢谢!这是可行的,但现在将委托设置为:void Light::setDelegate(float(fp)(char)){fpAction=fp;}会出现错误,我想我做错了。您需要更改委托调用,以便为成员函数指针使用适当的原型:float(Light::*fpAction)(char*)谢谢,您真的帮助了我。您能演示如何正确设置我的代理吗?(我对C++非常陌生),这是委托函数void Light::setDelegate(float(fp)(char)){set here}
float (Light::*fpAction)(char*) = 0 ;
float result = (b.*b.fpAction)("arg");