【问题标题】:Luabind compile time error Unable to deduce template argumentLuabind 编译时错误无法推断模板参数
【发布时间】:2014-11-20 10:10:10
【问题描述】:

我得到一个我不理解的编译时错误列表。我正在使用来自 sourceforge 的 luabind 库,版本 0.9.1,我正在尝试从 MyGUI 绑定函数,我正在使用 Visual Studio 2012 和 Lua 5.1。尽管似乎源自其他文件,但在编译下面的 cpp 代码期间会出现错误。这些错误让我认为我没有在某处正确定义签名,但我的 IntelliSense 并未指示任何此类问题。

有问题的代码:

LuaMachine.cpp(Stackoverflow抱怨body长度,所以我把它放在pastebin上)

给出的错误:

Error   4   error C2780: 'void luabind::detail::value_wrapper_converter<U>::apply(lua_State *,const T &)' : expects 2 arguments - 3 provided    c:\users\jake kiesel\space-junk\c++ project\3rdpartycode\include\luabind\detail\call.hpp    293 1   Space Junk
Error   3   error C2784: 'int luabind::detail::value_wrapper_converter<U>::match(lua_State *,luabind::detail::by_const_reference<T>,int)' : could not deduce template argument for 'luabind::detail::by_const_reference<T>' from 'luabind::detail::by_reference<T>' c:\users\jake kiesel\space-junk\c++ project\3rdpartycode\include\boost\preprocessor\iteration\detail\local.hpp  34  1   Space Junk
Error   2   error C2784: 'int luabind::detail::value_wrapper_converter<U>::match(lua_State *,luabind::detail::by_value<T>,int)' : could not deduce template argument for 'luabind::detail::by_value<T>' from 'luabind::detail::by_reference<T>' c:\users\jake kiesel\space-junk\c++ project\3rdpartycode\include\boost\preprocessor\iteration\detail\local.hpp  34  1   Space Junk
Error   6   error C2784: 'T luabind::detail::value_wrapper_converter<U>::apply(lua_State *,luabind::detail::by_const_reference<T>,int)' : could not deduce template argument for 'luabind::detail::by_const_reference<T>' from 'luabind::detail::by_reference<T>'   c:\users\jake kiesel\space-junk\c++ project\3rdpartycode\include\luabind\detail\call.hpp    293 1   Space Junk
Error   5   error C2784: 'T luabind::detail::value_wrapper_converter<U>::apply(lua_State *,luabind::detail::by_value<T>,int)' : could not deduce template argument for 'luabind::detail::by_value<T>' from 'luabind::detail::by_reference<T>'   c:\users\jake kiesel\space-junk\c++ project\3rdpartycode\include\luabind\detail\call.hpp    293 1   Space Junk

编辑:

通过进一步研究,我发现以下是触发这些错误的问题线。这些行在 wrapGuiManager 函数中。

luabind::def("destroyWidgets", &MyGUIManager::destroyWidgets)

luabind::def("unloadLayout", &MyGUIManager::unloadLayout),

这些是这些函数的函数声明:

void unloadLayout(luabind::object& table);

void destroyWidgets(luabind::object& table);

这两个函数的独特之处在于它们采用 luabind::object& 参数。他们应该能够从 Lua 中获取一个表,该表用作一个充满 MyGUI 小部件的数组。

【问题讨论】:

  • 我会尝试一次导出一个类和函数,直到找到导致错误的原因
  • 考虑到这个相当大的文件会有多么乏味,我真的很想避免这种情况,但它似乎是目前唯一的解决方案。
  • 使用该方法,我能够将问题隔离到 wrapGuiManager 函数。将继续研究此功能。
  • 您能否也发布 MyGUIManager::destroyWidgets 和 MyGUIManager::unloadLayout 的函数声明?
  • 完成。顺便说一句,感谢您与我一起度过难关。

标签: c++ visual-studio-2012 lua luabind


【解决方案1】:

我让它工作了! :D 问题是

luabind::def("destroyWidgets", &MyGUIManager::destroyWidgets)

luabind::def("unloadLayout", &MyGUIManager::unloadLayout)

这两个函数都使用了luabind::object&amp;,但luabind 不想与它们合作,而是希望这些函数在没有引用的情况下使用luabind::object,而只是对象本身。所以正确的函数声明应该是:

void unloadLayout(luabind::object table);
void destroyWidgets(luabind::object table);

【讨论】:

    猜你喜欢
    • 2013-12-09
    • 2010-10-17
    • 2020-01-21
    • 2010-12-22
    • 1970-01-01
    • 2012-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多