- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在尝试使用 Boost.Python 将我的 C++ 类公开给 Python。这是我正在尝试做的简单版本:
我有一个从 boost::noncopyable 派生的类 A 和第二个类 B,其方法将 A 的引用作为参数。
class A : boost::noncopyable { /*...*/ };
class B {
public:
virtual void do_something(A& a) {
/*...*/
}
};
我将这些类公开如下:
/* Wrapper for B, so B can be extended in python */
struct BWrap : public B, wrapper<B> {
void do_something(A &a) {
if (override do_something = this->get_override("do_something")) {
do_something(a);
return;
}
else {
B::do_something(a);
}
}
void default_do_something(A& a) { this->B::do_something(a); }
};
BOOST_PYTHON_MODULE(SomeModule) {
class_<A, boost::noncopyable>("A");
class_<BWrap, boost::noncopyable>("B")
.def("do_something", &B::do_something, &BWrap::default_do_something)
;
}
我像这样在python中扩展B:
test.py:
import SomeModule
class BDerived(SomeModule.B):
def do_something(self, a):
pass
并像这样调用扩展的 B:
try {
py::object main = py::import("__main__"); \
py::object global(main.attr("__dict__")); \
py::object result = py::exec_file("test.py", global, global); \
py::object pluginClass = global["BDerived"]; \
py::object plugin_base = pluginClass(); \
B& plugin = py::extract<B&>(plugin_base) BOOST_EXTRACT_WORKAROUND;
A a;
B.do_something(a);
}
catch (py::error_already_set) {
PyErr_Print();
}
但是这会导致错误消息:
TypeError: No to_python (by-value) converter found for C++ type: A
如果 A
不是从 boost::noncopyable
派生的,则代码运行没有任何错误,但 do_something(A& a)
中的参数 a > 在函数调用期间被复制,即使它是通过引用传入的。但仅仅删除对 A
的不可复制要求并不是一种选择,因为它的存在是有原因的。
有什么解决问题的建议吗?
谢谢。
最佳答案
将 B.do_something(a);
改为 B.do_something(boost::ref(a));
.
见 Calling Python Functions and Methods在 boost 手册中。
关于c++ - 通过引用 : TypeError: No to_python (by-value) converter found for C++ type: 调用 Boost.Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5336942/
我正在使用SpringBoot和JPA来调用db,我遇到异常 org.springframework.core.convert.ConverterNotFoundException: No conve
我尝试实现 Spring Converter,但在单元测试中出现错误: Kotlin: Null can not be a value of a non-null type TodoItem 如果我尝
我在 Spring Boot 2.0 示例中使用 Spring Data Redis。在此示例中,我尝试将客户数据 + 学生数据保存在一起。我不太确定这里的数据建模是如何发生的,但假设它与 Mongo
我在 Spring 的 XML 配置文件之一中有以下代码:
我们正在尝试使用 hibernate Converter 来加密/解密通过 hibernate 存储的几列数据 @Convert(attributeName="myattr",converter=Da
我有this我必须实现的功能: protected override ValidationResult IsValid( Object value, ValidationContext
我看到了 std::convert::Into有任何实现 std::convert::From 的实现: impl Into for T where U: From, 在Rust 1.0标准库
Convert.ChangeType 或 Convert.ToInt32 或 int.Parse 之间是否存在性能优势 最佳答案 如果您知道要将 string 转换为 Int32,使用 Convert
我会定期浏览我的家庭作业以供上课。我的扫描仪将原始 jpg 文件导出到 USB,然后我可以从那里使用 gimp 编辑文件并将其另存为 pdf。我发现一种节省时间的方法是将我的多页作业导出为 .mng
Grails版本:2.3.8我在BootStrap.groovy中注册了一个自定义日期编码器,但是当我使用日期填充为Json的Object时,它将引发异常:Exception message is C
我会定期浏览我的家庭作业以供上课。我的扫描仪将原始 jpg 文件导出到 USB,然后我可以从那里使用 gimp 编辑文件并将其另存为 pdf。我发现一种节省时间的方法是将我的多页作业导出为 .mng
我正在尝试制作一个 SKAction,以便我的玩家慢慢地被拉向一个要杀死他的敌人。实际上,问题在于玩家和敌人处于不同的节点,遵循以下层次结构: 场景(SKScene)-PARENT->播放器(SKNo
我通过 xml 设置了 spring data mongo 自定义转换器,如下所示 在自定义读/写转换器中,我想
我正在尝试使用名为 Simple Captcha 的 gem 这需要在机器上安装 ImageMagick。我已经安装了它并且 convert --version 显示了这个 Version: Imag
我正在尝试使用名为 Simple Captcha 的 gem 这需要在机器上安装 ImageMagick。我已经安装了它并且 convert --version 显示了这个 Version: Imag
我正在使用 Spring JPA,我需要有一个 native 查询来调用存储过程。从结果中,我只需要获取两个字段,即代码和消息。我创建了一个包含两个字段代码和消息的类。它不起作用,这是我收到的错误:
我首先有多部分文件,我想将其发送到camel管道并使用原始名称保存该文件。 我的代码: @Autowired ProducerTemplate producerTemplate; ...
我的maven项目使用了spring、hibernate。我得到“没有这样的方法错误”。我相信这是由于依赖项中的版本冲突造成的,但不知道是什么。构建成功。但是在“NetBeans:在 GlassFis
TL;DR:Vaadin 8 中是否有类似于 Vaadin 7 的转换器来更新 UI 中输入字段的表示? IE。在输入字段失去焦点后立即从用户输入中删除所有非数字,或将小数转换为货币? Vaadin
我昨天问了一个问题here关于从匿名对象读取属性并将它们写入类的私有(private)字段。问题解决了。这是一个小故事: 我有一些 json 格式的数据。我将它们反序列化为 ExpandoObject
我是一名优秀的程序员,十分优秀!