Python 调用 C++,python调用,#include <bo
Python 调用 C++,python调用,#include #include <boost/python.hpp>#include <boost/python/module.hpp>#include <boost/python/def.hpp>#include <boost/python/to_python_converter.hpp>#includeusing namespace std;using namespace boost::python;namespace HelloPython{// 简单函数char const* sayHello(){ return "Hello from boost::python";}// 简单类class HelloClass{public: HelloClass(const string& name):name(name){ }public: string sayHello(){ return "Hello from HelloClass by : " + name; }private: string name;};// 接受该类的简单函数string sayHelloClass(HelloClass& hello){ return hello.sayHello() + " in function sayHelloClass";}//STL容器typedef vector<int> ivector;//有默认参数值的函数void showPerson(string name,int age=30,string nationality="China"){ cout << name << " " << age << " " << nationality << endl;}// 封装带有默认参数值的函数BOOST_PYTHON_FUNCTION_OVERLOADS(showPerson_overloads,showPerson,1,3) //1:最少参数个数,3最大参数个数// 封装模块BOOST_PYTHON_MODULE(HelloPython){ // 封装简单函数 def("sayHello",sayHello); // 封装简单类,并定义__init__函数 class_("HelloClass",init()) .def("sayHello",&HelloClass::sayHello)//Add a regular member function ; def("sayHelloClass",sayHelloClass); // sayHelloClass can be made a member of module!!! // STL的简单封装方法 class_("ivector") .def(vector_indexing_suite()); class_ >("ivector_vector") .def(vector_indexing_suite >()); // 带有默认参数值的封装方法 def("showPerson",showPerson,showPerson_overloads());}
#include <boost/python.hpp>#include <boost/python/module.hpp>#include <boost/python/def.hpp>#include <boost/python/to_python_converter.hpp>#includeusing namespace std;using namespace boost::python;namespace HelloPython{// 简单函数char const* sayHello(){ return "Hello from boost::python";}// 简单类class HelloClass{public: HelloClass(const string& name):name(name){ }public: string sayHello(){ return "Hello from HelloClass by : " + name; }private: string name;};// 接受该类的简单函数string sayHelloClass(HelloClass& hello){ return hello.sayHello() + " in function sayHelloClass";}//STL容器typedef vector<int> ivector;//有默认参数值的函数void showPerson(string name,int age=30,string nationality="China"){ cout << name << " " << age << " " << nationality << endl;}// 封装带有默认参数值的函数BOOST_PYTHON_FUNCTION_OVERLOADS(showPerson_overloads,showPerson,1,3) //1:最少参数个数,3最大参数个数// 封装模块BOOST_PYTHON_MODULE(HelloPython){ // 封装简单函数 def("sayHello",sayHello); // 封装简单类,并定义__init__函数 class_("HelloClass",init()) .def("sayHello",&HelloClass::sayHello)//Add a regular member function ; def("sayHelloClass",sayHelloClass); // sayHelloClass can be made a member of module!!! // STL的简单封装方法 class_("ivector") .def(vector_indexing_suite()); class_ >("ivector_vector") .def(vector_indexing_suite >()); // 带有默认参数值的封装方法 def("showPerson",showPerson,showPerson_overloads());}
相关内容
- print &quot;hello python&quot;,,print "hello
- 将华氏温度转换成摄氏温度,或者相反,华氏摄氏,#-
- 用XML_RPC实现P2P,XML_RPC实现P2P,# -*- coding
- 有道词典导出的xml生词本文件提取出单词,xml生词,im
- python通过PIL缩放互联网上的图片并保存,,python通过PI
- python将html表格转换成CSV,pythonhtml表格csv,python将html表
- 原 第三方Linux版网易云音乐 出新版了,第三方linux,pr
- 基于Python的地图坐标服务接口调用代码实例,python坐标
- 删除指定格式的文件,删除指定格式文件,#!/usr/bin/p
- 翻页抓取,,#!/usr/bin/e
评论关闭