views:

86

answers:

2

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)
A: 

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?

Nikko
A: 

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:

.def("push_back", static_cast<void (std::vector<unsigned int>::*)(const unsigned int)>(&std::vector<unsigned int>::push_back))

(not 100% sure of details, but thats the general gist of it...)

Marcus Lindblom