【发布时间】:2021-01-28 22:07:54
【问题描述】:
我有以下代码:
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
class A {
public:
int f();
int (A::*x)();
};
int A::f() {
return 1;
}
int main() {
A a;
a.x = &A::f;
printf("%d\n",(a.*(a.x))());
}
我可以在哪里正确初始化函数指针。但是我想让函数指针成为静态的,我想在这个类的所有对象中维护它的单个副本。 当我将其声明为静态时
class A {
public:
int f();
static int (A::*x)();
};
我不确定将其初始化为函数 f 的方式/语法。任何资源都会有所帮助
【问题讨论】:
标签: c++ class function-pointers member-function-pointers