2024-09-30 18:14:00 发布
网友
我使用了SWIG,从C++代码中生成了Python库,遇到了以下错误:
TypeError: in method 'new_SpikeGeneratorFromVector', argument 1 of type 'std::vector< int,std::allocator< int > >'
我已经包括了接口文件std_vector.I和stl.I以及其他一些似乎必要的文件。当我向函数传递一个整数列表时,我得到了上面的错误。在
感谢任何帮助。在
这可能有助于:
/* File : example.i */ %module example %{ #include "example.h" %} %include "std_vector.i" namespace std { %template(IntVector) vector<int>; } %include "example.h" /*example.h*/ void my_func(std::vector<int> v) { for (int i=0; i<v.size(; i++)) std::cout<<v[i]<<"\n"; } /*in runme.py*/ import example # call with a python list: print example.my_func([1, 2, 3, 4]) #call with a python tuple: print example.my_func((1, 2, 3, 4)) # ... or a wrapped std::vector<int> v = example.IntVector(4) for i in range(len(v)): v[i] = i + 1 print example.my_func(v)
这可能有助于:
相关问题 更多 >
编程相关推荐