【发布时间】:2015-03-22 11:54:15
【问题描述】:
我正在尝试将成员函数指针传递给 c 风格的函数(因为它是 C 中的 lib)
它想要的指针定义为:
void (*)(int, const char*)
所以我要传递的函数是:
void Application::onError(int error, const char *description)
我正在尝试使用此代码传递它:
setCallback(bind(&Game::onError, this, placeholders::_1, placeholders::_2));
这给了我以下错误:
cannot convert ‘std::_Bind_helper<false, void (Application::*)(Application*, int,
const char*), Application* const, const std::_Placeholder<1>&, const
std::_Placeholder<2>&>::type {aka std::_Bind<std::_Mem_fn<void (Application::*)
(Application*, int, const char*)>(Application*, std::_Placeholder<1>,
std::_Placeholder<2>)>}’ to ‘GLFWerrorfun {aka void (*)(int, const char*)}’ for
argument ‘1’ to ‘void (* glfwSetErrorCallback(GLFWerrorfun))(int, const char*)’
glfwSetErrorCallback(bind(&Application::onError, this, placeholders::_1, placeholders::_2));
有什么方法可以成功地将成员函数作为绑定函数传递给 c 风格的函数?
【问题讨论】:
标签: c++ c pointers c++11 callback