digitalmars.D - Help on passing a function to a function pointer.
- Kirill (29/29) Mar 23 2021 I am exploring GLFW with D (bindbc-glfw). I faced the following
- Paul Backus (5/12) Mar 23 2021 You're trying to pass a pointer to a member function (a
- Kirill (2/14) Mar 23 2021 Thank you! That worked!
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?
 Mar 23 2021
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.
 Mar 23 2021
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:Thank you! That worked!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.
 Mar 23 2021








 
  
  
  Kirill <kirill.saidov mail.com>
 Kirill <kirill.saidov mail.com>