c++于python混合系统的一个难题
这是一个普通的混合使用方式, 但这种方式不能达到脚本真正的灵活性, c++每个属性必须绑定一个唯一的set和get接口提供给python内部访问这个属性
C/C++ code:
class sample
{
public:
int m_obj;
int GetValue(){
return m_obj;
}
void SetValue(int v){
m_obj= v;
}
};
class_<sample>("sample")
.add_property("m_obj", &sample::GetValue, &sample::SetValue )
我看过一个公司做的一个系统使用自己开发的python插件模块实现了非常灵活的c++与python交互
这个系统有一个配置文件, 其中定义着一些属性和接口, 在系统启动时会去分析这些配置然后把它们
建立在python中, 用户在python中对这些配置定义的属性赋值都会被c++所截获
下面是按照我的设想去做, 当然下面代码不能运行 因为不支持这样的方式。
用户在配置文件定义了3个属性
int obj1, float obj2, string obj3
把它们绑定到一个通用的接口上
.add_property("obj1", &bind(&sample::GetValue, 1), &bind(&sample::SetValue, 1 ) )
.add_property("obj2", &bind(&sample::GetValue, 2), &bind(&sample::SetValue, 2 ) )
.add_property("obj3", &bind(&sample::GetValue, 3), &bind(&sample::SetValue, 3 ) )
class sample
{
public:
Py
相关问答:
请问用C或C++如何编写求解3D魔方的程序,该从何开始?
谢谢各位,帮忙提点建议吧。
http://www.mofang.net/code/176/182/6581.html
我只能突破60秒!唉。
我刚过40秒
google的android中有个OpenGL ES + ......
python和pyqt以及Eric4都已经配置好了,打开Eric4写个python程序比如简单的
print“hello,world”,怎么编译运行了,Start菜单的所有命令都出现和图中差不多的对话框,应当怎么运行了?
求大家指教
没有人用 ......
已知Python 中:
s = unicode("测试", "gb2312")
s = u'\u6d4b\u8bd5'
print s
测试
在Delphi里面如何将\u6d4b\u8bd5这样的还原成Gb2312的汉字呢?
找到个方法
......
请问下,我的是python2.5安装了PIL模块,然后编写程序打开本机上的一个图片时,为什么老出现错误呢,老是找不到图片,错误提示如下:File "C:\Python25\Lib\site-packages\PIL\Image.py", line 1888, in o ......
#include "stdio.h"
int main()
{
char *ch(char *, char *);
char str1[]="I am glad to meet you!";
char str2[]="Welcom to study C!";
&nb ......