2

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?

3
  • 2
    If this really is C++ and not C++0x, please make sure you include a space between the closing angle brackets. eg >> should be > > Commented Sep 21, 2010 at 15:47
  • 1
    I was debating to comment or answer... Commented Sep 21, 2010 at 15:49
  • 1
    Duplicate of stackoverflow.com/questions/3754922/… ? Commented Jan 3, 2011 at 4:32

1 Answer 1

4

Is it a C++ parsing issue?

 std::vector<std::vector<MyClass*> >;
 ---Important space---------------^
Sign up to request clarification or add additional context in comments.

2 Comments

Also this line was needed in the interface file: %template(VectorOfStructVector) vector<vector<MyClass*> >;
@Javier, another solution is to compile with "--std=c++0x" if you're using gcc. C++0x has fixed this problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.