Home > Back-end >  Ask is there a way to call a class member function of the variable to a function pointer outside of
Ask is there a way to call a class member function of the variable to a function pointer outside of

Time:05-18

Tried to STD: : the function of target function is not workable,
If there is one, and then further, have not a layer of overall quality function solution package?

CodePudding user response:

Here are the answers
A lambda can only be converted to A function pointer if it does not capture, the from the draft standard c + + 11 section 5.1.2 [expr. Prim. Lambda] says (emphasis mine) :

The closure type for a lambda expression - with no lambda - The capture from a public non - virtual non - explicit const conversion function to pointer to The function having The same parameter and return types as The closure type 's function call operator. The value returned by this conversion function shall be The address of a function that, when invoked, has The same effect as invoking The closure type' s function call operator.

https://www.apiref.com/cpp-zh/cpp/utility/functional/function/target.html

CodePudding user response:

Do you want to get a private function pointer?

CodePudding user response:

Talk is being. Show me the code.

CodePudding user response:

 
Own handwriting class:
Bool Windows: : Init ()
{
.
FunctionIf (fun. TargetCout & lt; <"Fun null \ n";
GlfwSetFramebufferSizeCallback (window, fun. Target
//glfwSetCursorPosCallback (window, MouseCallback);
//glfwSetScrollCallback (window, ScrollCallback);
.
}

Void Windows: : FrameBufferSizeCallBack (GLFWwindow * Window, int width, int height)
{
GlViewport (0, 0, width, height);
}

Call API interface:
GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback (GLFWwindow * window, GLFWframebuffersizefun callback);

GLFWframebuffersizefun is a function pointer form:
Typedef void (* GLFWwindowmaximizefun) (GLFWwindow *, int);




CodePudding user response:

reference 1st floor 丁劲犇 response:

here are answerA lambda can only be converted to A function pointer if it does not capture, the from the draft standard c + + 11 section 5.1.2 [expr. Prim. Lambda] says (emphasis mine) :

The closure type for a lambda expression - with no lambda - The capture from a public non - virtual non - explicit const conversion function to pointer to The function having The same parameter and return types as The closure type 's function call operator. The value returned by this conversion function shall be The address of a function that, when invoked, has The same effect as invoking The closure type' s function call operator.

https://www.apiref.com/cpp-zh/cpp/utility/functional/function/target.html

Share the lambda function statement, is not

CodePudding user response:

refer to the second floor NorZ response:
do you want to get a private function pointer?

Is this meaning
  • Related