无法得到它。使用 g++ 编译器。
代码:
#include <iostream>
using namespace std;
typedef void (* FPTR) ();
class Test
{
void f1()
{
cout << "Do nothing 1" << endl;
}
void f2()
{
cout << "Do nothing 2" << endl;
}
static FPTR const fa[];
};
FPTR const Test::fa[] = {f1, f2};
错误:
test.cpp:22: error: argument of type ‘void (Test::)()’ does not match ‘void (* const)()’
test.cpp:22: error: argument of type ‘void (Test::)()’ does not match ‘void (* const)()’
我只想获得函数指针的常量数组,所以
fa[0] = f2;
会导致类似'modifying read-only member Test::fa'的错误