Boost.Python:使用继承
An example
#include <boost/python.hpp>
#include <memory>
#include <iostream>
using namespace std;
using namespace boost::python;
#define show(x) cout << x << endl
struct Base{
Base() { show("Base+"); }
virtual ~Base() { show("Base-"); }
virtual const char* name() const {
return "Base";
}
};
struct Derived : Base{
int x;
Derived() : x(123) { show("Derived+"); }
~Derived() { show("Derived-"); }
virtual const char* name() const {
return "Derived";
}
};
shared_ptr<Base> derived_as_base(){
return shared_ptr<Base>(new Derived);
}
const char* get_name(const Base& b){
return b.name();
}
int get_derived_x(const Derived& d){
return d.x;
}
BOOST_PYTHON_MODULE(foo_ext){
class_<Base, shared_ptr<Base>>("Base"); // should provide HeldType
class_<Derived, bases<Base>>("Derived");
def("derived_as_base", derived_as_base);
def("get_name", get_name);
def("get_derived_x", get_derived_x);
}
Reference
Boost.Python:使用继承的更多相关文章
- boost.python入门教程 ----python 嵌入c++
Python语言简介 Python是一种脚本语言.以开放的开发接口和独特的语法著称.尽管Python在国内引起注意只有几年的时间,但实际上Python出现于上世纪90年代(据www.python.or ...
- [转]vs2010用 boost.python 编译c++类库 供python调用
转自:http://blog.csdn.net/wyljz/article/details/6307952 VS2010建立一个空的DLL 项目属性中配置如下 链接器里的附加库目录加入,python/ ...
- 使用Boost.Python构建混合系统(译)
目录 Building Hybrid Systems with Boost.Python 摘要(Abstract) 介绍(Introduction) 设计目标 (Boost.Python Design ...
- boost.python笔记
boost.python笔记 标签: boost.python,python, C++ 简介 Boost.python是什么? 它是boost库的一部分,随boost一起安装,用来实现C++和Pyth ...
- Boost.Python简介
Boost.Python简单概括:是Boost库的一部分:用来在C++代码中调用python代码以及在Python代码中调用C++代码,并且避免用户直接操作指针. 以下内容搬运自:https://wi ...
- sqlalchemy mark-deleted 和 python 多继承下的方法解析顺序 MRO
sqlalchemy mark-deleted 和 python 多继承下的方法解析顺序 MRO 今天在弄一个 sqlalchemy 的数据库基类的时候,遇到了跟多继承相关的一个小问题,因此顺便看了一 ...
- python基础——继承和多态
python基础——继承和多态 在OOP程序设计中,当我们定义一个class的时候,可以从某个现有的class继承,新的class称为子类(Subclass),而被继承的class称为基类.父类或超类 ...
- 编译boost python模块遇到的错误:../../libraries/boost_1_44_0/boost/python/detail/wrap_python.hpp:75:24: fatal error: patchlevel.h: No such file or directory
就是遇到类似标题上面的错误. 原因是没有安装对应python的python-dev依赖,不然编译到boost python模块的时候就会出错. 所以解决方案是sudo apt-get install ...
- [修]python普通继承方式和super继承方式
[转]python普通继承方式和super继承方式 原文出自:http://www.360doc.com/content/13/0306/15/9934052_269664772.shtml 原文的错 ...
随机推荐
- Jquery如何获取控件ID
l 1.#id 用法: $(”#myDiv”); 返回值 单个元素的组成的集合 说明: 这个就是直接选择html中的id=”myDiv” l 2.Element 用法: ...
- windows 7 旗舰版 切换 中英文 界面
http://jingyan.baidu.com/article/f7ff0bfc4963612e26bb131e.html 如果遇到:想下载英语语言包,但是出现代码80070643,windowsu ...
- PL/SQL分页查询
create or replace procedure fenye(tabelname in varchar2,currentpage in number,pageSize in number,inW ...
- eclipse ldt update resource
http://download.eclipse.org/ldt/releases/milestones/ 百度一下都说是 http://download.eclipse.org/koneki/upda ...
- [Effective Modern C++] Item 7. Distinguish between () and {} when creating objects - 辨别使用()与{}创建对象的差别
条款7 辨别使用()与{}创建对象的差别 基础知识 目前已知有如下的初始化方式: ); ; }; }; // the same as above 在以“=”初始化的过程中没有调用赋值运算,如下例所示: ...
- USB驱动开发
1.usb特点 2.usb class 3.
- webpy + nginx + fastcgi 构建python应用
1.准备环境 CentOs 6.3 nginx-1.4.2.tar.gz http://nginx.org/download/nginx-1.4.2.tar.gz openss ...
- Wordpress 常用代码解释
1. 最新文章 Wordpress最新文章的调用可以使用一行很简单的模板标签 wp_get_archvies来 实现. 代码如下: <?php get_archives('postbypost' ...
- CKfinder中文乱码的解决.
最近在写一个类似博客的系统,使用了ckeditor和ckfinder,但是发现ckfinder在上传中文文件名的文件过程中会出现中文乱码的情况. 于是百度google乎,发现大多数的解决办法都是将文件 ...
- A Simple Task
A Simple Task Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...