MSVC 10 +卢宾德std::vector == 拒绝编译
所以,我有一个代码,在 MSVC 9 和一些以前的版本上编译(不知道它可以追溯到多远...),GCC,MingW,Mac 上的 GCC...
但是有一行代码不能在 MSVC 上编译:
class_< vector<unsigned int> >("LayerList")
.def(constructor<>())
.def("GetCount", &vector<unsigned int>::size)
.def("Get", &NumberGet)
.def("Add", &vector<unsigned int>::push_back) //this line refuses to compile
.def("__tostring", &LayerListToString)
如果我评论它,应用程序编译得很好(但在运行时中断),如果我将此块移动到其他地方(甚至在其他文件中),则该特定行会不断给出错误...更改块内的顺序也不能解决问题。
它给出了 9 个错误,其中大多数是关于 .def 中的参数数量错误(有人说有 2 个参数,而它预期是 1、3、5,一个说“参数太多”),还有一些是关于重载失败,最明显的是一:
错误 7 错误 C2914:'luabind::class_::def':无法推导模板参数,因为函数参数不明确 E:\novashellSVN\clanlibstuff\novashell\source\ListBindings.cpp 178
这让我浪费了整个工作日...有人知道 MSVC 10 上发生了什么变化导致了这种情况吗?它不再困扰我,因为工作被卡住了,而是因为它是多么令人困惑和奇怪。
编辑:我将 MSVC 10 中的“矢量”文件与其他 MSVC 和 GCC 进行了比较,实际上在 MSVC 中它有 3 个版本,有人确切地知道我如何让它加载特定版本?
三个版本:
void push_back(const _Ty& _Val) //the one in GCC and older MSVC, thus the one I want
void push_back(_Ty&& _Val)
void push_back(bool _Val)
So, I have a code, that compiled on MSVC 9 and some previous (dunno how far back it goes...), GCC, MingW, GCC on Mac...
But one line, does not compile on MSVC:
class_< vector<unsigned int> >("LayerList")
.def(constructor<>())
.def("GetCount", &vector<unsigned int>::size)
.def("Get", &NumberGet)
.def("Add", &vector<unsigned int>::push_back) //this line refuses to compile
.def("__tostring", &LayerListToString)
If I comment it, the application compiles fine (but breaks at runtime), if I move this block somewhere else (even in other files) this particular line keeps giving errors... changing the order inside the block does not solve it too.
It gives 9 errors, most of them about wrong number of arguments in .def (some say there are 2 arguments when it expected 1, 3, 5 and one says "too much arguments"), and some about overloading failing, the most obvious one:
Error 7 error C2914: 'luabind::class_::def' : cannot deduce template argument as function argument is ambiguou E:\novashellSVN\clanlibstuff\novashell\source\ListBindings.cpp 178
This made me waste the entire work day... Someone has any clue on what changed on MSVC 10 to cause this? It is not anymore even bugging me because of the work stuck, but because how puzzling and strange it is.
EDIT: I compared the "vector" file, from MSVC 10, with other MSVC and GCC, and indeed in MSVC it has 3 versions, someone know EXACTLY how I make it load a specific version?
The three versions:
void push_back(const _Ty& _Val) //the one in GCC and older MSVC, thus the one I want
void push_back(_Ty&& _Val)
void push_back(bool _Val)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 Nikko 所说,您必须选择正确的过载。这有点像 C++ PITA。
使用 static_cast<>将 Push_back 转换为正确类型的 ptr-to-mem-fn 。即类似于以下内容:(
不是 100% 确定细节,但这就是它的一般要点......)
As Nikko says, you must select the correct overload. This is a bit of C++ PITA.
Use static_cast<> to cast push_back to a ptr-to-mem-fn of the correct type. i.e. something like the following:
(not 100% sure of details, but thats the general gist of it...)
如果您有重载函数,则必须通过将“&vector::push_back”转换为正确的函数来指定要使用的函数。您必须检查 luabind 文档的语法。
也许现在有几种名为“push_back”的方法,您必须指定使用哪一种?
If you have overloaded functions you must specify which you want to use by casting "&vector::push_back" to the correct function. You must check luabind documentation for the syntax.
Maybe now there is several methods named "push_back" and you must specify which one to use?