0

我正在尝试创建一个函数指针数组来减轻一些否则会是噩梦的代码。我想使用一组函数,如下面的函数。

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

如果我将函数定义为静态,它会起作用,但我真的不能这样做,因为它会对我的设计产生太大影响。我该如何解决这个问题?

4

1 回答 1

0

由于右侧显示的建议,我找到了答案。

鉴于我想使用指向类 Grid 的成员函数的指针,我必须在 typedef 声明中指定它。

typedef void(Grid::*FunctionPointer)(Point2, Point2, Point2, Point2);

注意之前丢失的Grid:: 。

于 2013-11-01T14:28:59.810 回答