1
假設我正在連接到C.如何傳遞extern(C)函數字面值?
這是接口的包裝功能。
@property extern(C) void onEvent(void function(InterfaceStruct*, int, int, int) nothrow callback)
{
interfaceSetCallback(handle, callback);
}
一切都好。
wrapper.onEvent = function void (InterfaceStruct*, int x, int y, int z) nothrow
{
if (x == 11) doSomething();
};
嗯哦:
Error: function foo.bar.onEvent (void function(InterfaceStruct*, int, int, int) nothrow callback) is not callable using argument types (void function(InterfaceStruct* _param_0, int x, int y, int z) nothrow @nogc @safe)
所以,要我有函數文本是的extern(C)。那我該怎麼做?我找不到任何方法來這樣做。
嘿,謝謝!我無法在網上找到關於函數指針或文字的太多內容。另外,感謝您提供的第二個選項。我已經知道了那個(在查看其他代碼之後),但我並沒有儘可能地使用cast。幸運的是,現在,我不需要。 –