gpt4 book ai didi

c++ - 返回引用的导出函数

转载 作者:搜寻专家 更新时间:2023-10-31 00:20:54 25 4
gpt4 key购买 nike

我想导出到 python 模块(用 c++ 编写,带有 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方法编译成功,但是 DotNormalize返回同样的错误(在编译期间):

 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<>)’

我做错了什么?


UPD

真正的类名是:CL_Vec<Type> , 这里是 docs .

最佳答案

如果你看vec2.h (或您链接到的文档),您会看到 dotnormalize 都重载了,因为它们也存在 static 版本.

您可以使用一些函数指针来解决这个问题:

Vec2<int> &(Vec2<int>::*norm)() = &Vec2<int>::normalize;

然后在 def 中使用它,如 here 所述.

关于c++ - 返回引用的导出函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5369135/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com