导出返回引用的函数
我想把一个用C++写的函数导出到Python模块中,这个模块使用了boost.python库。
Vec2<Type> &normalize ()
Type dot(const Vec2<Type> &vector) const
这些是模板类 Vec2
的成员。下面是我的导出代码:
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
方法编译成功,但 Dot
和 Normalize
在编译时都出现了同样的错误:
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<>)’
我哪里做错了?
更新
真实的类名是: CL_Vec<Type>
,这里是 文档。
2 个回答
2
当编译器说:
<unresolved overloaded function type>
看看你的成员指针或者函数指针(比如 &Vec2::dot),确认它是不是指向一组重载函数(应该是的)。在这种情况下,你可能需要明确地使用 static_cast<> 来转换成特定的成员指针或函数指针类型,包括函数的参数类型。