試過std::function的target函式不可行。
如果有的話,再進一步,有沒有不包一層全域性質的函式的解決辦法?
uj5u.com熱心網友回復:
這里有答案A lambda can only be converted to a function pointer if it does not capture, from the draft C++11 standard section 5.1.2 [expr.prim.lambda] says (emphasis mine):
The closure type for a lambda-expression with no lambda-capture has a public non-virtual non-explicit const conversion function to pointer to 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
uj5u.com熱心網友回復:
你是想拿到私有函式的指標?uj5u.com熱心網友回復:
Talk is cheap. Show me the code.uj5u.com熱心網友回復:
自己手寫的類:
bool Window::Init()
{
...
function<void(GLFWwindow*, int, int)> fun = bind(&Window::FrameBufferSizeCallBack, this, _1, _2, _3);
if (fun.target<void(GLFWwindow*, int, int)>() == nullptr)
cout << "fun null \n";
glfwSetFramebufferSizeCallback(window, fun.target<void(GLFWwindow*, int, int)>());
//glfwSetCursorPosCallback(window, MouseCallback);
//glfwSetScrollCallback(window, ScrollCallback);
...
}
void Window::FrameBufferSizeCallBack(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
}
呼叫的API介面:
GLFWAPI GLFWframebuffersizefun glfwSetFramebufferSizeCallback(GLFWwindow* window, GLFWframebuffersizefun callback);
GLFWframebuffersizefun是函式指標形式:
typedef void (* GLFWwindowmaximizefun)(GLFWwindow*,int);
uj5u.com熱心網友回復:
函式陳述句比較多,是不是不適合用lambda
uj5u.com熱心網友回復:
對就這意思
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/284220.html
標籤:C++ 語言
上一篇:VC2019 為啥一直是白屏呢
