私のプロジェクトではGLFW3を使用しています。そして、私は、関数GLFWSetKeyCallbackにC++ 11ラムダを与えようとしています。これはパラメータとしてGFLWwindowをとり、GLFWfunkey関数はtypedefです。 void(* GLFWkeyfun)(GLFWwindow *、int、int、int、 int)。ラムダをGLFWkeyfunとして使用
機能が私のWindowクラスから呼び出され、ここでコード
window.hpp
class Window
{
public:
Window(GLuint width, GLuint height, std::string title);
~Window();
GLFWwindow* get() { return window_.get(); }
bool is_open() { return open_; };
void close();
private:
bool open_ = false;
std::unique_ptr<GLFWwindow, DestroyWindow> window_;
std::vector<Drawable*> drawables_;
};
そしてwindow.cpp
#include <pck/window.hpp>
Window::Window(GLuint width, GLuint height, std::string title) :
open_(true)
{
window_.reset(glfwCreateWindow(width, height, title.c_str(), nullptr, nullptr));
glfwMakeContextCurrent(window_.get());
Global::width = width;
Global::height = height;
glfwSetKeyCallback(window_.get(), [this](GLFWwindow* window, int key, int scancode, int action, int mode){
for(auto it : drawables_)
it->input(window, key, scancode, action, mode);
});
}
Window::~Window()
{
window_.reset();
}
void
Window::close()
{
open_ = false;
window_.reset();
}
とコンパイラ(打ち鳴らす++ 3.8からの誤差があります.1)
fatal error: no matching function for call to 'glfwSetKeyCallback'
glfwSetKeyCallback(window_.get(), [this](GLFWwindow* window, i...
^~~~~~~~~~~~~~~~~~
/usr/include/GLFW/glfw3.h:3307:20: note: candidate function not viable: no
known conversion from '(lambda at
/path/to/file.cpp)' to
'GLFWkeyfun' (aka 'void (*)(GLFWwindow *, int, int, int, int)') for 2nd argument
GLFWAPI GLFWkeyfun glfwSetKeyCallback(GLFWwindow* window, GLFWkeyfun cbfun);
誰かが私が間違っていたことを私に指摘できますか?
ありがとうございます!
は役に立つかもしれませんします。http://stackoverflow.com/a/39622958/434551。 –