为什么不能使用std :: ref将对象传递给Boost.Python模块?
发布时间:2020-12-20 13:12:46 所属栏目:Python 来源:网络整理
导读:环境:使用 Python 3.5编译Boost 1.61.0 以下C代码输出12: class A{public: int func() { return 12; }};BOOST_PYTHON_MODULE(bridge){ using namespace boost::python; class_A("A",no_init) .def("func",A::func);}int main(){ A a; PyImport_AppendInitt
环境:使用
Python 3.5编译Boost 1.61.0
以下C代码输出12: class A { public: int func() { return 12; } }; BOOST_PYTHON_MODULE(bridge) { using namespace boost::python; class_<A>("A",no_init) .def("func",&A::func); } int main() { A a; PyImport_AppendInittab("bridge",PyInit_bridge); Py_Initialize(); using namespace boost::python; dict dictMain = extract<dict>(import("__main__").attr("__dict__")); import("bridge").attr("a") = boost::ref(a); exec("import bridge",dictMain); exec("print(bridge.a.func())",dictMain); } 但是,如果我用std :: ref替换b??oost :: ref,则抛出boost :: python :: error_already_set实例. 为什么不能在这里使用std :: ref? 解决方法
很好的文章关于
handling python exceptions in C++.任何方式我猜python异常AttributeError,因为
std和
boost库中的reference_wrapper实现的差异.即使在公共界面中也可以看到差异. std :: reference_wrapper没有get_pointer()方法.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |