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 原文的错 ...
随机推荐
- 伪元素::selection(怎么修改网页中被选中文本的样式)
当我们用鼠标选中一段文字的时候我们会发现文字的颜色和背景色都改变了, 有时候设计给这种选中状态设计了其他的样式,那么我们怎么来自定义选中的文本的样式呢? 用::selection <p>我 ...
- ASP.NET通用权限组件思路设计
开篇 做任何系统都离不开和绕不过权限的控制,尤其是B/S系统工作原理的特殊性使得权限控制起来更为繁琐,所以就在想是否可以利用IIS的工作原理,在IIS处理客户端请求的某个入口或出口通过判断URL来达到 ...
- JQ 无刷新评论
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- C++ 析构函数为虚函数
1.原因: 在实现多态时, 当用基类指针操作派生类, 在析构时候防止只析构基类而不析构派生类. 2.例子: (1). #include<iostream> using namespace ...
- JavaScript事件属性绑定带参数的函数
JavaScript中在对事件进行绑定的时候,往往是element.onclick=event;这种形式,这样使用的话则会出现无法传参数.因此我们可以使用function(){}匿名函数将事件包含其中 ...
- final的深入理解 - final数据
先通过例子看一看: package com.sotaof.testfinal; public class Value { int i; public Value(int i){ this.i = i; ...
- Velocity中避免null引起的数据问题
请先看下面一段代码: #foreach($id in [1..50]) #set($user = $User.Get($id)) $id : ${user.name} #end 上面这段代码中,假设只 ...
- [汇编语言]-第九章 根据位移进行转移的jmp指令 段内短转移 段内近转移 段间转移(远转移) 转移的目的地址在指令中,在寄存器中,在内存中的jmp指令
1- jmp为无条件转移指令,可以只修改IP, 也可以同时修改CS和IP jmp指令要给出两种信息: (1) 转移的目的地址 (2) 转移的距离(段间转移, 段内转移, 段内近转移) 2- 依据位移进 ...
- python 的内建函数
lambda 函数:lambda语句中,冒号前是参数,可以有多个,用逗号隔开,冒号右边的返回值 1. map/reduce 函数 (1)map()函数接收两个参数,一个是函数,一个是序列,map将传入 ...
- C语言基础09
指向结构体变量的指针叫做结构体指针: typedef struct { int num; char name[30]; // char *name; 程序会崩溃,*name本身是指针,没有什么空 ...