I want to export into python module (written in c++, with boost.python开发者_如何学Python library) such function:
Vec2<Type> &normalize ()
Type dot(const Vec2<Type> &vector) const
These are the members of template class Vec2
. Here is my export code:
bp::class_< Vec2<int> >("Vec2i", bp::init<int, int>())
.def("Length", &Vec2<int>::length)
.def("Dot", &Vec2<int>::dot, bp::return_internal_reference<>());
//.def("Normalize", &Vec2<int>::normalize);
Length
method compiles successful, but Dot
and Normalize
returns same mistake (during compiling):
error: no matching function for call to ‘boost::python::class_<Vec2<int> >::def(const char [4], <unresolved overloaded function type>, boost::python::return_internal_reference<>)’
What I did wrong?
UPD
The real class name is: CL_Vec<Type>
, here is the docs.
If you look at vec2.h
(or the docs you link to), you'll see that dot
and normalize
are both overloaded, since there also exist static
versions of these.
You can get around this by using a few function pointers:
Vec2<int> &(Vec2<int>::*norm)() = &Vec2<int>::normalize;
and then using that in the def
, as explained here.
When the compiler says:
<unresolved overloaded function type>
Take a look at your pointer-to-member or function pointer (&Vec2::dot) and see if it refers to a set of overload functions (it should). In this case you may need an explicit static_cast<> to the specific pointer-to-member or function pointer type, including function parameter types.
精彩评论