1
我试图使用D的等价函数指针作为一种方式来指定可选函数作为结构中的一个字段,其中我正在初始化一个数组。这在C中很简单(除了混乱的语法外),但我被卡住了。这个程序:编译器错误与D的等价函数指针
struct Foo {
ubyte code;
bool yup;
void function(ubyte[] data, int size) special;
}
void boof(ubyte[] data, int size) {
/*do something*/
}
static immutable Foo[] markdefs = [
{0xF2, true, null},
{0xE4, true, boof},
{0xEE, false, null}
];
void main() {
}
给了我这些错误:
funptr.d(17): Error: function funptr.boof (ubyte[] data, int size) is not
callable using argument types()
funptr.d(17): Error: expected 2 function arguments, not 0
funptr.d(17): called from here: boof()
funptr.d(17): Error: cannot implicitly convert expression (boof()) of type
void to void function(ubyte[] data, int size)
我使用DMD为D2 64位Linux机器上。