boost python - Python 缓冲区到 C++标准::字符串
我有一个 C++ 函数,它接受一个 std::string 作为参数和一个作为缓冲区的 python 对象。我以为我可以直接传递缓冲区,并且 Boost Python 会自动将其转换为字符串,但事实并非如此:
Boost.Python.ArgumentError: Python argument types in
mod.decrypt(buffer)
did not match C++ signature:
decrypt(std::string string_to_decrypt)
是否有必要为此编写转换器?我以为它会隐式转换。感谢您的任何建议。
I have a C++ function that takes one std::string as an argument and a python object that is a buffer. I thought that I could pass the buffer directly and that Boost Python would convert it to a string automatically, but it does not:
Boost.Python.ArgumentError: Python argument types in
mod.decrypt(buffer)
did not match C++ signature:
decrypt(std::string string_to_decrypt)
Is it necessary to write converters for this? I thought it would implicitly convert. Thanks for any advice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误消息说明了一切 - 您的签名是一个字符串,但您向它传递了一个缓冲区。
它不会内省对象来确定如何转换它 - 缓冲区可以是任何东西。
你需要转换它。
The error message says it all - your signature is a string, but you're passing it a buffer.
It's not going to introspect the object to determine how to convert it - buffer could be anything.
You need to convert it.