Boost python,从另一个类的方法返回一个类
Boost python, returning a class from a method of another class
我的问题是我有两个类似的类
class B{
public:
double x,y;
}
class A{
public:
B foo();
}
BOOST_PYTHON_MODULE(interestingLib){
class_<A>("A")
.def("foo", &A::foo)
;
class_<B>("B")
.def_readonly("x",&B::x)
.def_readonly("y",&B::y)
;
}
在我的python脚本中,我调用函数foo
并得到返回,然后我想看到成员变量x
,就像这个一样
A = interestingLib.A
B = A.foo()
B.x
但是我得到错误AttributeError: 'NoneType' object has no attribute 'x'
有人能告诉我问题出在哪里吗?
在python中,您应该使用
A = interestingLib.A()
而不是
A = interestingLib.A
此代码A = interestingLib.A
分配给类型为Boost.Python.class
的A
对象。使用A = interestingLib.A()
可以创建具有默认构造函数的A
类型的对象。
相关文章:
- C++,class,一个返回对象的函数
- C++ 这里有一个返回 (24) 的布尔返回类型函数
- 我有一个返回字符串向量的函数.它需要两个字符串,并且返回一个字符串中缺少的字符串
- 两个相同的重载运算符[]一个返回引用
- 给定一个整数 N>0,区间 [0, 2^N) 中有多少个整数正好有 N-1 个设置位?编写一个返回正确答案的简短函数
- 为什么要定义一个返回结构的 lambda 函数,而不是直接定义结构
- 有没有办法重写一个返回指向 istringstream 的指针的函数,而不是返回一个引用?
- 提升:创建一个返回变体的函数
- C++重载运算符两次,一个返回非常量引用,另一个返回常量引用,首选项是什么
- 我是否应该将最后一个“返回”语句封装为“else { return .. }',如果它在逻辑上是可选的
- 野牛解析器:创建一个返回令牌的函数
- 为什么 C++ 数组的大小不能有一个返回常量的函数调用
- 如何创建一个返回传递的参数名称的函数
- 如何在C++中创建一个返回字节数组的函数?Arduino项目
- 将返回的指针分配给另一个返回的指针
- 如何声明一个返回类型是推导出来的函数
- Constexpr语言 - 为什么只是一个返回语句
- 如何创建一个返回护士函数的函数
- 如何用C包装一个返回智能指针的C++函数
- 如何使用两个函数,一个返回迭代器,另一个返回const_iterator