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:使用继承的更多相关文章

  1. boost.python入门教程 ----python 嵌入c++

    Python语言简介 Python是一种脚本语言.以开放的开发接口和独特的语法著称.尽管Python在国内引起注意只有几年的时间,但实际上Python出现于上世纪90年代(据www.python.or ...

  2. [转]vs2010用 boost.python 编译c++类库 供python调用

    转自:http://blog.csdn.net/wyljz/article/details/6307952 VS2010建立一个空的DLL 项目属性中配置如下 链接器里的附加库目录加入,python/ ...

  3. 使用Boost.Python构建混合系统(译)

    目录 Building Hybrid Systems with Boost.Python 摘要(Abstract) 介绍(Introduction) 设计目标 (Boost.Python Design ...

  4. boost.python笔记

    boost.python笔记 标签: boost.python,python, C++ 简介 Boost.python是什么? 它是boost库的一部分,随boost一起安装,用来实现C++和Pyth ...

  5. Boost.Python简介

    Boost.Python简单概括:是Boost库的一部分:用来在C++代码中调用python代码以及在Python代码中调用C++代码,并且避免用户直接操作指针. 以下内容搬运自:https://wi ...

  6. sqlalchemy mark-deleted 和 python 多继承下的方法解析顺序 MRO

    sqlalchemy mark-deleted 和 python 多继承下的方法解析顺序 MRO 今天在弄一个 sqlalchemy 的数据库基类的时候,遇到了跟多继承相关的一个小问题,因此顺便看了一 ...

  7. python基础——继承和多态

    python基础——继承和多态 在OOP程序设计中,当我们定义一个class的时候,可以从某个现有的class继承,新的class称为子类(Subclass),而被继承的class称为基类.父类或超类 ...

  8. 编译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 ...

  9. [修]python普通继承方式和super继承方式

    [转]python普通继承方式和super继承方式 原文出自:http://www.360doc.com/content/13/0306/15/9934052_269664772.shtml 原文的错 ...

随机推荐

  1. LINQ 操作符(二)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  2. javascript动态创建对象

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. Hibernate 查询:HQL查询(Hibernate Query Languge)

    HQL是一种面向对象的查询语言,其中没有表和字段的概念,只有类,对象和属性的概念. 使用HQL查询所有学生: public static void main(String[] args) { Sess ...

  4. iOS之极光推送

    注册JPush账号 JPush官网 下载SDK 下载地址:https://www.jpush.cn 根据文档进行集成 文档:http://docs.jpush.io/guideline/ios_gui ...

  5. C - Big Number

    Description In many applications very large integers numbers are required. Some of these application ...

  6. auto 和 decltype (C++11 新增)

    红色字体为个人推断,可信度自辨. 蓝色字体为重点. auto类型说明符:使用auto时,编译器会分析表达式,并自动推算出变量所属类型.*auto变量必须有初值 原理:编译器通过 初值 来判断auto变 ...

  7. 正式学习React (六) 项目篇

    https://github.com/huenchao/yingshili 或者点这里 注意事项看ReadME.md 会持续更新,反正就是把之前分析的redux react-redux都用一下,然后会 ...

  8. javascript 事件设计模式

    http://plkong.iteye.com/blog/213543 1. 事件设计概述 事件机制可以是程序逻辑更加清晰可见,在JavaScript中很多对象都有自己的事件,如:button有onc ...

  9. 基于HCE移动支付研究报告

    1. 概念 HCE(host-based card emulation),即基于主机的卡模拟.在一部配备NFC功能的手机实现卡模拟,目前有两种方式:一种是基于硬件的,称为虚拟卡模式(Virtual C ...

  10. System.Web.Caching.Cache类 缓存 各种缓存依赖

    原文:System.Web.Caching.Cache类 缓存 各种缓存依赖 Cache类,是一个用于缓存常用信息的类.HttpRuntime.Cache以及HttpContext.Current.C ...