创建类的实例并传递给c++代码

Create a instance of class and pass to c++ code

本文关键字:c++ 代码 实例 创建      更新时间:2023-10-16

我有一个名为entity的类,它像这样:

class entity {
public:
 entity();
virtual ~entity();
virtual void draw();
virtual void init();
protected:
std::string name;
};

现在我想在python中创建一个类的实例,然后将其加载回c++,是否可以编写这样的函数:

entity* loadEntityFromPython(char *pythonscript); 

你可以试试boost::python。它为c++代码生成python绑定,以便在python中使用它。当然,也可以为基于c++的类生成python绑定。请查看文档:http://www.boost.org/doc/libs/1_55_0/libs/python/doc/tutorial/doc/html/python/exposing.html