【发布时间】:2016-06-29 23:58:42
【问题描述】:
这和this问题很相关
不管这是否是编码练习,我都遇到过类似这样的代码
test.hh
#include <vector>
using std::vector;
class Test
{
public:
vector<double> data;
};
我正在尝试使用 swig3.0 使用以下接口文件来痛饮它
test.i
%module test_swig
%include "std_vector.i"
namespace std {
%template(VectorDouble) vector<double>;
};
%{
#include "test.hh"
%}
%naturalvar Test::data;
%include "test.hh"
以及下面的测试代码
test.py
t = test.Test()
jprint(t)
a = [1, 2, 3]
t.data = a # fails
这样做会给我以下错误
in method 'Test_data_set', argument 2 of type 'vector< double >'
可以通过将 test.hh 中的 using std::vector 更改为 using namespace std 或删除 using std::vector 并将 vector<double> 更改为 std::vector<double> 来解决此问题。这不是我想要的。
问题是我得到了这个代码。我不允许进行更改,但我仍然应该通过 SWIG 在 python 中提供所有内容。这里发生了什么?
提前致谢。
【问题讨论】:
-
将 using 语句放在头文件中是不行的,你正在找出原因。
标签: python c++ c++11 vector swig