包装C+时,GLFWwindow类型不完整+;班 我试图从Python中获得一个代码:>代码/> C++类基类,用Boosi::Python和AM来包装GLFW回调,特别是由于GLFWLWORK>窗口< /C> >参数>
以下是MCVE:包装C+时,GLFWwindow类型不完整+;班 我试图从Python中获得一个代码:>代码/> C++类基类,用Boosi::Python和AM来包装GLFW回调,特别是由于GLFWLWORK>窗口< /C> >参数> ,c++,boost-python,C++,Boost Python,以下是MCVE: #define GLFW_INCLUDE_NONE #include <GLFW/glfw3.h> #include <boost/python.hpp> class Application { public: Application(); GLFWwindow* window; virtual int onKeyPressed(GLFWwindow*, int, int, int , int); }; Applicatio
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#include <boost/python.hpp>
class Application
{
public:
Application();
GLFWwindow* window;
virtual int onKeyPressed(GLFWwindow*, int, int, int , int);
};
Application *app;
Application::Application()
{
glfwInit();
window = glfwCreateWindow(800.0, 600.0, "example", NULL, NULL);
glfwMakeContextCurrent(window);
}
int Application::onKeyPressed(GLFWwindow *window, int key, int scancode, int action, int mods)
{
return 1;
}
struct ApplicationWrap : Application, boost::python::wrapper<Application>
{
int onKeyPressed(GLFWwindow *window, int key, int scancode, int action, int mods)
{
return this->get_override("onKeyPressed")(window, key, scancode, action, mods);
}
};
static void _onKeyPressed(GLFWwindow *window, int key, int scancode, int action, int mods)
{
app->onKeyPressed(window, key, scancode, action, mods);
}
int main() {
// app = new Application();
// glfwSetKeyCallback(app->window, _onKeyPressed);
// delete app;
return 0;
}
BOOST_PYTHON_MODULE(example)
{
namespace python = boost::python;
python::class_<ApplicationWrap, boost::noncopyable>("Application")
//.def("onKeyPressed", _onKeyPressed).staticmethod("_onKeyPressed")
;
}
// import example
// class DerivedApplication(example.Application):
// def __init__(self):
// example.Application.__init__(self)
// def onKeyPressed(window):
// print("successfully overrides example.Application.onKeyPressed.")
// DerivedApplication()
错误:无效使用不完整的类型“struct GLFWwindow”
类型ID(T)
^~~~~~~~~
注意:“struct GLFWwindow”typedef struct的转发声明
GLFWwindow GLFWwindow
感谢您提供有关如何解决此问题的任何反馈。错误来自
模板内联类型\u info type\u id()
通过
template <class T>
struct registered_pointee
: registered<
typename boost::python::detail::remove_pointer< // <-- fails for incomplete types
typename boost::python::detail::remove_cv<
typename boost::python::detail::remove_reference<T>::type
>::type
>::type
>
{
};
错误指向哪一行代码?您好,它发生在
intonkeypressed(…)
内部ApplicationWrap
。我试图写一个更全面的例子,因为我刚刚意识到,onKeyPressed
需要是静态的才能传递给glfwSetKeyCallback
。我必须仔细阅读它的工作原理。如果你想找代表,就把它变成答案。再次感谢!很高兴这有帮助。而且,是的,请查一下并仔细检查,因为我上次玩这些游戏已经有一段时间了,可能还有一些新的技巧我也需要学习。
template <class T>
struct registered_pointee
: registered<
typename boost::python::detail::remove_pointer< // <-- fails for incomplete types
typename boost::python::detail::remove_cv<
typename boost::python::detail::remove_reference<T>::type
>::type
>::type
>
{
};
BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(GLFWwindow)