类的成员函数hello::greet 和普通函数invite 的声明写法不一样,如下
BOOST_PYTHON_MODULE(getting_started)
{
// 尖括号里的hello标识c++代码中的hello类
// "hello"表示在python中的类名
// init表示python类hello的构造函数
// <std::string>表示python类hello构造函数的参数
class_<hello>("hello", init<std::string>())
.def("greet", &hello::greet); // 成员函数,同时使用&指明
def("invite", invite);//普通函数
}
假如普通函数依赖某个库,需要加上头文件以及编译需要链接库(如 -ludev)