[C++-sig] Problem exposing 2D python array in C++

alfa alfarobi0161 at yahoo.com
Wed Aug 15 15:05:17 CEST 2012


Hi,


Is the following way valid to expose a 2D array variable from python (Vp)  to c++(Vp_cpp)?
   

std::vector<std::vector<double> > Vp_cpp;
boost::python::class_<std::vector<std::vector<double> > >("PyVec").def(boost::python::vector_indexing_suite<std::vector<std::vector<double> > >());


main_namespace["Vp"] = boost::python::ptr(&Vp_cpp);

But, then if I tried to manipulate the 2D vector in C++ like the following, it doesn't work:

Vp_cpp[1][1] = 999;
std::cout << "Vp_cpp[1][1] = " << Vp_cpp[1][1] << std::endl;  // It doesn't print to


What could be wrong or am I missing something?

Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20120815/b4ca7a4c/attachment.html>


More information about the Cplusplus-sig mailing list