为什么 std::ref 不能用于将对象传递到 Boost.Python 模块中?
Why can't std::ref be used to pass objects into Boost.Python modules?
环境:Boost 1.61.0使用Python 3.5编译
以下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);
}
但是,如果我将boost::ref
替换为std::ref
,则抛出boost::python::error_already_set
实例。
为什么这里不能使用std::ref
?
关于在c++中处理python异常的好文章。无论如何,我猜python通过异常AttributeError
,因为reference_wrapper
在std和boost库中的实现不同。即使在公共界面上也可以看到差异。std::reference_wrapper
没有get_pointer()
方法
相关文章:
- 我应该包含什么来制作 boost.python 扩展?
- C++ 和 Boost.Python - 如何将变量公开给 python 并在循环中更新它?
- 如何将来自 Boost.Python 的map_indexing_suite与自定义而不是标准对象一起使用?
- Boost Python Numpy - 要初始化的未定义引用
- Boost.Python :C++模板类型匹配的嵌套命名空间
- Boost.Python 列出了所有公开的类和属性
- Boost.Python 在静态库方面失败
- 在cpp中使用boost-python的python代码是否进行动态内存分配
- Boost.Python 和导入 dll,"The specified module could not be found"
- 无法将__str__特殊方法与Boost::Python接口
- 编译时出现Boost.python链接错误
- 使用 Boost/Python 的未定义符号 - 复杂
- Boost.Python 和C++导入到 Python 3 时编译库错误
- 两个并发的 Python 进程可以在 Boost Python 中运行吗?
- 通过 Boost Python 将 Python 函数转换为 C++,用作回调
- 编译在 Python 代码内部调用的 C++ 代码时出错,使用 Boost Python
- Boost.Python.ArgumentError: World.set(World, str) 中的 Python
- 使用 boost python 从 c++ 为 python 中的类成员变量赋值
- Boost Python 不断链接 Python27 库
- 使用 python3 为 msvc 构建 boost python - 链接器错误