我在继承使用boost::python生成的python类时遇到了一个问题。在
我有一个类,其函数Print()的定义如下:
void CMagnet::Print()
{
cout << "Hello" << endl;
}
接口在我的.cpp文件中定义如下:
^{pr2}$原则上,该模块可以工作,但我遇到了继承方面的问题。下面是一个例子:
from CMagnet import CMagnet
class DerMagnet(CMagnet):
def __init__(self):
self.Print()
a = CMagnet()
a.Print()
b = DerMagnet()
我得到的是:
hirbel>;python der_测试.py在
Hello
Traceback (most recent call last):
File "der_test.py", line 10, in <module>
b = DerMagnet()
File "der_test.py", line 5, in __init__
self.Print()
Boost.Python.ArgumentError: Python argument types in
CMagnet.Print(DerMagnet)
did not match C++ signature:
Print(CMagnet {lvalue})
这意味着当我实例化CMagnet类时,可以毫无问题地调用Print()方法,但是当我从它继承并且派生类尝试调用该方法时,self参数会自动作为第一个参数插入,签名是错误的。我该如何解决这个问题?在
非常感谢你的帮助。在
我确认@kerim的评论。在
如果不调用父类“\uuInit”方法,就会得到这种错误消息。在
相关问题 更多 >
编程相关推荐