我正在尝试用 STL 队列类替换用 Lua 编写的队列类的现有实现。我不确定为什么会失败,或者如何解决它。下面是一些表现出相同行为的示例代码,以及错误输出。提前致谢!
#include <luabind/luabind.hpp> #include <queue> struct XYZ_T { short x, y, z; }; typedef std::queue<XYZ_T> XYZ_QUEUE_T; extern "C" int init(lua_State *L) { using namespace luabind; open(L); module(L) [ class_<XZY_T>("XYZ_T") .def(constructor<>()) .def_readwrite("x", &XYZ_T::x) .def_readwrite("y", &XYZ_T::y) .def_readwrite("z", &XYZ_T::z), class_<XYZ_QUEUE_T>("XYZ_QUEUE_T") .def(constructor<>()) .def("push", &XYZ_QUEUE_T::push) .def("pop", &XYZ_QUEUE_T::pop) .def("front", &XYZ_QUEUE_T::front) .def("back", &XYZ_QUEUE_T::back) .def("empty", &XYZ_QUEUE_T::empty) .def("size", &XYZ_QUEUE_T::size) ]; }
以及 gcc 输出:
g++ -o test_luabind.os -c -fPIC -Iinclude -I$VALID_INCLUDE_DIR /packages/build_env/include test_luabind.cpp test_luabind.cpp: In function `int init(lua_State*)': test_luabind.cpp:27: error: no matching function for call to ` luabind::class_<XYZ_QUEUE_T, luabind::detail::unspecified, luabind::detail::unspecified, luabind::detail::unspecified>::def(const char[6], <unknown type>)' test_luabind.cpp:32: error: parse error before `(' token
最佳答案
很可能,您的队列实现中有一个重载函数。因此,当您获取地址时,编译器不知道该怎么做,因为您可能指的是任何重载函数。
关于c++ - 通过 Luabind 将 STL 队列暴露给 Lua,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6604022/