Wrap std::vector of std::vectors, C++ SWIG Python

2019-05-20 04:18发布

问题:

I want to wrap a C++ vector of vectors to Python code by using SWIG.

Is it possible to wrap this type of vector of vectors?

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

In the interface file MyApplication.i I added these lines:

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

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

But, I'm getting an Error when SWIG is executed. I'm able to wrap this type (using reference to the vector):

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

But, it's not working properly, I cannot access the items. That's why I'm interested in this type (without the reference):

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

Any ideas?

回答1:

Is it a C++ parsing issue?

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