Thread overview | |||||
---|---|---|---|---|---|
|
March 24, 2021 Help on passing a function to a function pointer. | ||||
---|---|---|---|---|
| ||||
I am exploring GLFW with D (bindbc-glfw). I faced the following problem: I need to set the frame buffer size callback: `glfwSetFramebufferSizeCallback(GLFWwindow*, extern (C) void function(GLFWwindow*, int, int) nothrow)` I have created a function: `extern (C) void setFrameBufferSizeCallback(GLFWwindow* window, int w, int h) nothrow { glfwViewport(0, 0, w, h); }` And then: `glfwSetFramebufferSizeCallback(window, &setFrameBufferSizeCallback)` DMD produces the following error: `source/display.d(59,32): Error: function pointer glfwSetFramebufferSizeCallback(GLFWwindow*, extern (C) void function(GLFWwindow*, int, int) nothrow) is not callable using argument types (GLFWwindow*, extern (C) void delegate(GLFWwindow* window, int w, int h) nothrow) source/display.d(59,32): cannot pass argument &this.frameBufferSizeCallback of type extern (C) void delegate(GLFWwindow* window, int w, int h) nothrow to parameter extern (C) void function(GLFWwindow*, int, int) nothrow dmd failed with exit code 1. ` What should I do? I have read the available information on D function pointers, but I still can't get it working. What am I missing? |
March 24, 2021 Re: Help on passing a function to a function pointer. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kirill | On Wednesday, 24 March 2021 at 02:41:39 UTC, Kirill wrote:
> DMD produces the following error:
> `source/display.d(59,32): Error: function pointer glfwSetFramebufferSizeCallback(GLFWwindow*, extern (C) void function(GLFWwindow*, int, int) nothrow)
> is not callable using argument types
> (GLFWwindow*, extern (C) void delegate(GLFWwindow* window, int w, int h) nothrow)
You're trying to pass a pointer to a member function (a "delegate"), but it expects a pointer to a non-member function. Either make the function `static` or move it outside the class/struct it's currently in.
|
March 24, 2021 Re: Help on passing a function to a function pointer. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paul Backus | On Wednesday, 24 March 2021 at 03:06:15 UTC, Paul Backus wrote:
> On Wednesday, 24 March 2021 at 02:41:39 UTC, Kirill wrote:
>> DMD produces the following error:
>> `source/display.d(59,32): Error: function pointer glfwSetFramebufferSizeCallback(GLFWwindow*, extern (C) void function(GLFWwindow*, int, int) nothrow)
>> is not callable using argument types
>> (GLFWwindow*, extern (C) void delegate(GLFWwindow* window, int w, int h) nothrow)
>
> You're trying to pass a pointer to a member function (a "delegate"), but it expects a pointer to a non-member function. Either make the function `static` or move it outside the class/struct it's currently in.
Thank you! That worked!
|
Copyright © 1999-2021 by the D Language Foundation