我正在尝试创建一个函数指针数组来减轻一些否则会是噩梦的代码。我想使用一组函数,如下面的函数。
void drawNothing(Point2, Point2, Point2, Point2);
我已经为函数指针定义了一个类型。
typedef void(*FunctionPointer)(Point2, Point2, Point2, Point2);
还有一个数组来存储指针本身。
FunctionPointer drawMSCase[16];
问题是当我尝试将功能分配给其中一个插槽时,就像这样
drawMSCase[0] = &Grid::drawNothing;
我收到以下错误
error: cannot convert 'void (Grid::*)(Point2, Point2, Point2, Point2)' to 'Grid::FunctionPointer {aka void (*)(Point2, Point2, Point2, Point2)}' in assignment
如果我将函数定义为静态,它会起作用,但我真的不能这样做,因为它会对我的设计产生太大影响。我该如何解决这个问题?