【问题标题】:Wrap std::vector of std::vectors, C++ SWIG Python包装 std::vector 的 std::vectors,C++ SWIG Python
【发布时间】:2010-09-21 15:31:17
【问题描述】:

我想使用 SWIG 将向量的 C++ 向量包装到 Python 代码中。

这种类型的向量可以包装吗?

std::vector<std::vector<MyClass*>>;

在接口文件MyApplication.i我添加了这些行:

%include "std_vector.i"
%{ 
#include <vector> 
%} 

namespace std {
   %template(VectorOfStructVector) vector<vector<MyClass*>>;
}

但是,执行 SWIG 时出现错误。我能够包装这种类型(使用对向量的引用):

 std::vector<std::vector<MyClass*>*>;

但是,它无法正常工作,我无法访问这些项目。这就是为什么我对这种类型感兴趣(没有参考):

 std::vector<std::vector<MyClass*>>;

有什么想法吗?

【问题讨论】:

  • 如果这确实是 C++ 而不是 C++0x,请确保在右尖括号之间包含一个空格。例如&gt;&gt; 应该是&gt; &gt;
  • 我正在讨论评论或回答...

标签: c++ python vector swig


【解决方案1】:

是 C++ 解析问题吗?

 std::vector<std::vector<MyClass*> >;
 ---Important space---------------^

【讨论】:

  • 接口文件中也需要这一行: %template(VectorOfStructVector) vector >;
  • @Javier,如果您使用 gcc,另一种解决方案是使用“--std=c++0x”进行编译。 C++0x 已经解决了这个问题。
猜你喜欢
  • 1970-01-01
  • 2016-12-05
  • 1970-01-01
  • 2020-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-19
  • 2021-12-16
相关资源
最近更新 更多