Boost.Python能将C++的结构体暴露给Python使用。但是在运用Boost.Python时,却遇到一个难题,
1、在C++定义一个新的结构体struct A
2、将此结构体暴露给Python解释器
3、如今在工程中生成结构体A的对象,A a。
4、希望将a传入Python解释器进行运算,运算的函数写在某py文件中。
一直没有办法解决,希望大虾帮助解答。
这个问题就是在c++中调用py实现的接口函数。
类似c++代码
struct a
{
int a ;
int b;
};
a temp;
GetPythonFunc( & temp ); //调用python函数,参数为一定结构体的引用.
这个结构体用boost可以导出给python. 但是这个参数要怎么传递给python代码呢?
最后在python mailist找到答案
--------------------------------------------------
#include
#include
using namespace boost::python;
class World
{
public:
void set(std::string msg) { this->msg = msg; }
std::string greet() { return msg; }
std::string msg;
};
typedef boost::shar