1

我使用 C++ 编写了一个简单的排序函数,它的声明是 void sort(int *, int) 我使用 cppyy 在 python 函数中使用 C++ 扩展,文档告诉我可以在需要时使用 array.array传递内置数据指针类型。但它总是提示:

Traceback (most recent call last):

  File "app_main.py", line 51, in run_toplevel

  File "test.py", line 13, in <module>

    m.sort(ai, 1)

TypeError: none of the 1 overloaded methods succeeded. Full details:

  void MyClass::sort(int*, int) =>

    TypeError: no converter available

这是我写的python代码:

#coding=utf8
import cppyy
import time
from array import array

cppyy.load_reflection_info("libMyClassDict.so")

MyClass = cppyy.gbl.MyClass
m = MyClass()
start = time.time()

m = MyClass()

for i in xrange(10000000):
    ai = array('i', [23])
    m.sort(ai, 1)
    m.SetMyInt(312, 2315, 2135, 13, 3251, 54, 2134, 3253, 134, 3251);

end = time.time()
print end - start

任何人都可以解决我的问题?

4

0 回答 0