Python的C/C++扩展——boost_python编写Python模块
前面讲述了Python使用ctypes直接调用动态库和使用Python的C语言API封装C函数,本文概述方便封装C++类给Python使用的boost_python库。 安装boost python库: sudo aptitude install libboost-python-dev 示例 下面代码简单实现了一个普通函数maxab()和一个Student类: #include <iostream> #include <string> int maxab(int a, int b) { return a>b?a:b; } class Student { private: int age; std::string name; public: Student() {} Student(std::string const& _name, int _age) { name=_name; age=_age; } static void myrole() { std::cout << "I'm a student!" << std::e...