Boost.Python.ArgumentError: World.set(World, str) 中的 Python
Boost.Python.ArgumentError: Python argument types in World.set(World, str) did not match C++ signature: set(World {lvalue}, std::string)
I am learning boost-python from the Tutorial,
但是遇到错误,你能给我一些提示吗,谢谢!
#include <boost/python.hpp>
using namespace boost::python;
struct World
{
void set(std::string msg) { this->msg = msg; }
std::string greet() { return msg; }
std::string msg;
};
BOOST_PYTHON_MODULE(hello)
{
class_<World>("World")
.def("greet", &World::greet)
.def("set", &World::set)
;
}
蟒蛇终端:
>>> import hello
>>> planet = hello.World()
>>> planet.set('howdy')
错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Boost.Python.ArgumentError: Python argument types in
World.set(World, str) did not match C++ signature:
set(World {lvalue}, std::string)
使用来自 [Boost Python 的演示代码 教程][1][1]
: https://www.boost.org/doc/libs/1_51_0/libs/python/doc/tutorial/doc/html/python/exposing.html
将程序更改为代码,如下所示,它将起作用
#include <boost/python.hpp>
using namespace boost::python;
struct World
{
World(){}; // not mandatory
void set(std::string msg) { this->msg = msg; }
std::string greet() { return msg; }
std::string msg;
};
BOOST_PYTHON_MODULE(hello)
{
class_<World>("World", init<>()) /* by this line
your are giving access to python side
to call the constructor of c++ structure World */
.def("greet", &World::greet)
.def("set", &World::set)
;
}
相关文章:
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- Pybind11:将元组列表从Python传递到C++
- 如何在c++中使用引用实现类似python的行为
- 是否可以通过C++扩展强制多个python进程共享同一内存
- 递归列出所有目录中的C++与Python与Ruby的性能
- IPC使用多个管道和分支进程来运行Python程序
- 从python中调用C++函数并获取返回值
- Python 3.7 和 excess_args 的 SWIG 问题
- Python中的for循环与C++有何不同
- 使用Pybind11向Python公开Eigen::张量
- Python str to C++ to Python str
- 如何使用Python从C++中读取谷物序列化数据
- 如何在C++中使用pybind11加载一个pickle python列表
- 如何在c++中使用system()来运行包含空格的python脚本
- python集合的C++等价物是什么.计数器
- 如何使用python运行Hello world c ++代码
- Boost.Python.ArgumentError: World.set(World, str) 中的 Python
- 使用boost.python构建Hello World
- 用Homebrew在Mac OS X上构建python boost hello world-Makefile vs.Re
- Hello World Python 扩展在 C++ 中使用 boost